Crombie, Joe
2007-Sep-21 00:27 UTC
[R] Time series graphs, question about using zoo [SEC=UNCLASSIFIED]
Hi Fang, An easy way of doing this is by:> matplot(one, pch = LETTERS[1:4], type = 'b')Cheers Joe Joe Crombie Information and Risk Sciences Bureau of Rural Science Canberra Australia p: +61 2 6272 5906 e: joe.crombie at brs.gov.au -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of fang liu Sent: Friday, 21 September 2007 8:35 AM To: r-help at r-project.org Subject: Re: [R] Time series graphs, question about using zoo 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 9So 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" <ggrothendieck at gmail.com> >To: "Bill Pepe" <sonicbill12 at yahoo.com> >CC: r-help at 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 <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 areessentially 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. > > > >______________________________________________ >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._________________________________________________________________ [[replacing trailing spam]] ______________________________________________ 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. ------IMPORTANT - This message has been issued by The Department of Agriculture, Fisheries and Forestry (DAFF). The information transmitted is for the use of the intended recipient only and may contain confidential and/or legally privileged material. It is your responsibility to check any attachments for viruses and defects before opening or sending them on. Any reproduction, publication, communication, re-transmission, disclosure, dissemination or other use of the information contained in this e-mail by persons or entities other than the intended recipient is prohibited. The taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you have received this e-mail in error please notify the sender and delete all copies of this transmission together with any attachments. If you have received this e-mail as part of a valid mailing list and no longer want to receive a message such as this one advise the sender by return e-mail accordingly. Only e-mail correspondence which includes this footer, has been authorised by DAFF ------