Thanks for all the help on my earlier questions..... How do you plot a simple time series with unequal intervals? I have the following dateofpoll <- as.ts(c("6/1/02", "7/1/02", "10/1/02", "1/4/03", "1/25/03", "6/7/03", "7/16/03", "8/17/03", "9/4/03")) reelect <- c(51, 47, 49, 51, 49, 49, 46, 45, 40) new <- c(28, 32, 35, 36, 41, 38, 47, 48, 52) what I'd like is to plot reelect and new (maybe with smoothing) on a time scale, with the x axis labeled for date..... But I can't figure out how, despite looking at ?ts and various things there Thanks in advance Peter L. Flom, PhD Assistant Director, Statistics and Data Analysis Core Center for Drug Use and HIV Research National Development and Research Institutes 71 W. 23rd St www.peterflom.com New York, NY 10010 (212) 845-4485 (voice) (917) 438-0894 (fax)
The Irregular Time-Series ('its') class could be helpful to you. The following does the basics of what you have asked. require(its) its.format("%m/%d/%y") myits <- its(cbind(reelect,new),dates=as.POSIXct(x=strptime(dateofpoll,format=its.for mat()))) plot(myits,type="b") You may want to customise the graphical parameters using par(), or passing extra parameters to plot() which will pass them through, to axis.POSIXct, for example to control the number of x-axis ticks, which in this example defaults to 1. On the smoothing issue, I can't really help. The its package is to be found on CRAN. Giles> -----Original Message----- > From: Peter Flom [mailto:flom at ndri.org] > Sent: 08 September 2003 22:08 > To: r-help at stat.math.ethz.ch > Subject: [R] Yet another beginner question > > > Thanks for all the help on my earlier questions..... > > > How do you plot a simple time series with unequal intervals? I have > the following > > dateofpoll <- as.ts(c("6/1/02", "7/1/02", "10/1/02", "1/4/03", > "1/25/03", > "6/7/03", "7/16/03", "8/17/03", "9/4/03")) > reelect <- c(51, 47, 49, 51, 49, 49, 46, 45, 40) > new <- c(28, 32, 35, 36, 41, 38, 47, 48, 52) > > what I'd like is to plot reelect and new (maybe with smoothing) on a > time scale, with the x axis labeled for date..... > > But I can't figure out how, despite looking at ?ts and various things > there > > > Thanks in advance > > > > > > Peter L. Flom, PhD > Assistant Director, Statistics and Data Analysis Core > Center for Drug Use and HIV Research > National Development and Research Institutes > 71 W. 23rd St > www.peterflom.com > New York, NY 10010 > (212) 845-4485 (voice) > (917) 438-0894 (fax) > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >********************************************************************** This is a commercial communication from Commerzbank AG.\ \ T...{{dropped}}
Peter Flom wrote:> Thanks for all the help on my earlier questions..... > > > How do you plot a simple time series with unequal intervals? I have > the following > > dateofpoll <- as.ts(c("6/1/02", "7/1/02", "10/1/02", "1/4/03", > "1/25/03", > "6/7/03", "7/16/03", "8/17/03", "9/4/03")) > reelect <- c(51, 47, 49, 51, 49, 49, 46, 45, 40) > new <- c(28, 32, 35, 36, 41, 38, 47, 48, 52) > > what I'd like is to plot reelect and new (maybe with smoothing) on a > time scale, with the x axis labeled for date..... > > But I can't figure out how, despite looking at ?ts and various things > there > > > Thanks in advanceYou can do it by converting to POSIX format, but a more convinient way is provided by the new contributed package "its" (Irregular Spaced Time-Series, on CRAN) by Giles Heywood (I have not tested it, though), see the announcement: https://www.stat.math.ethz.ch/pipermail/r-announce/2003/000768.html Uwe Ligges> Peter L. Flom, PhD > Assistant Director, Statistics and Data Analysis Core > Center for Drug Use and HIV Research > National Development and Research Institutes > 71 W. 23rd St > www.peterflom.com > New York, NY 10010 > (212) 845-4485 (voice) > (917) 438-0894 (fax) > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help