[R] Time series graphs

Gabor Grothendieck ggrothendieck at gmail.com
Thu Sep 20 20:15:54 CEST 2007


Using plot.zoo in the zoo package try this:

Lines <- "Bob.A         Bob.B            Tom.A        Tom.B
 Jan              8        4             9         8
 Feb             7         5             4         7
 Mar             6         8             4         4
 Apr             3         7              6         2
 May            5         1             8         5
 Jun             6         4              7        1
 July             2         8             3         4
 Aug             1        2              4         8
 Sep            4          3              1        9
"
DF <- read.table(textConnection(Lines))

library(zoo)
z <- zooreg(as.matrix(DF), start = as.yearmon(as.Date("2007-01-01")), freq = 12)
z <- aggregate(z, as.Date, tail, 1)
plot(z, plot.type = "single",  type = "o",
	pch = c("A", "A", "B", "B"), lty = 1:2)
legend("bottomleft", c("Bob", "Tom"), lty = 1:2)



On 9/20/07, Bill Pepe <sonicbill12 at yahoo.com> wrote:
> I'm fairly new to S-Plus and I need to get this done quickly. Suppose I have the following fake data below:
>
>  There are two companies, call them Bob and Tom. Each have two variables, call them A and B, that have observations.
>
>                         Bob                 Tom
>
>                    A         B            A        B
>  Jan              8        4             9         8
>  Feb             7         5             4         7
>  Mar             6         8             4         4
>  Apr             3         7              6         2
>  May            5         1             8         5
>  Jun             6         4              7        1
>  July             2         8             3         4
>  Aug             1        2              4         8
>  Sep            4          3              1        9
>
>  Here is what I want to do: I want to make two different graphs, one for Bob and one for Tom. For each graph, plot both variables A and B. Connect the A values with a line, and connect the B values with a different type of line. So there should be two lines for each graph. For the A line, at each time point, the letter A should be on the line. And the same goes for the B line. Either R or S-Plus since they are essentially the same.
>
>  I'm sure this is easy, but any help would be greatly appreciated.
>
>  Thanks,
>
>  Bill
>
>
> ---------------------------------
> Pinpoint customers who are looking for what you sell.
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list