Try this: Lines <- "A B C D 8 4 9 8 7 5 4 7 6 8 4 4 3 7 6 2 5 1 8 5 6 4 7 1 2 8 3 4 1 2 4 8 4 3 1 9 " one <- read.table(textConnection(Lines), header = TRUE) library(zoo) z <- zoo(as.matrix(one)) plot(z, plot.type = "single", pch = colnames(z), type = "o", col = 1:4, lty = 1:4) legend("bottomleft", colnames(z), col = 1:4, lty = 1:4)
# or use matplot matplot(as.matrix(one), pch = colnames(z), type = "o") legend("bottomleft", colnames(z), col = 1:4, lty = 1:4) On 9/20/07, fang liu <[EMAIL PROTECTED]> wrote: > Hi, > Can you tell me what is the meaning for "tail, 1" in "aggregate"? > I also want to get some similar graph, but the data is not time series data. > Suppose here is my data one, I want a graph with x-axis is just the > index(1:9). > The graph plot all the variable A, B,C,D. So there should be 4 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. > A B C D > > 8 4 9 8 > > 7 5 4 7 > > 6 8 4 4 > > 3 7 6 2 > > 5 1 8 5 > > 6 4 7 1 > > 2 8 3 4 > > 1 2 4 8 > > 4 3 1 9 > > So I add a name for each row > rownames(one) <- c(1:9) > z <- zooreg(as.matrix(one), start = 1, freq = 1) > z <- aggregate(z, as.Date, tail, 1) > plot(z, plot.type = "single", type = "o", > pch = c("A", "B", "C", "D"), lty = 1:2) > > I get the plot, which I think it should be right. but the problem is that > the x-axis still have month (Jan, ) on it and I didnot get "A,B,C,D" on my > graph, is there any thing wrong? > > > > >From: "Gabor Grothendieck" <[EMAIL PROTECTED]> > >To: "Bill Pepe" <[EMAIL PROTECTED]> > >CC: r-help@r-project.org > >Subject: Re: [R] Time series graphs > >Date: Thu, 20 Sep 2007 14:15:54 -0400 > > > >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 <[EMAIL PROTECTED]> 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@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. > > > > > > >______________________________________________ > >R-help@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. > > _________________________________________________________________ > [[replacing trailing spam]] > > ______________________________________________ > R-help@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. > ______________________________________________ R-help@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.