It would be great to get a detailed question. As far as I understood you wanted to plot your series in a single frame. There are plenty examples in the help of plot.ts and plot.zoo for that. I prefer working with time series be using the zoo package. But most things can also be done within ts. The packages lattice and ggplot2 offer further styles for plots
Try this: library(zoo) test <- structure(list(Date = structure(c(15657, 15664, 15678, 15700, 15713, 15720, 15734, 15741, 15755, 15769, 15783, 15790, 15811, 15832, 15839, 15853, 15867, 15880, 15895, 15902, 15916, 15930, 15944, 15951, 15958, 15965, 15972, 15979, 15986, 16000, 16014, 16021, 16028, 16035, 16042, 16049, 16056, 16065, 16077, 16084, 16091, 16105, 16112, 16126, 16141, 16147, 16154, 16161, 16175, 16189, 16203), class = "Date"), Inr = c(2.2, 2.5, 2.4, 2.3, 2.1, 1.9, 1.9, 3.3, 2.6, 2.7, 3.1, 2.4, 2, 2.5, 2.3, 2.4, 2.3, 2.3, 2.1, 2.4, 3.6, 3, 1.3, 2.6, 1.9, 3.4, 2.4, 2.2, 2.9, 2.8, 2.1, 2.2, 2.2, 3, 2.7, 2.3, 2.7, 2.9, 2.7, 2.6, 2.6, 3.3, 2.6, 2.8, 2.9, 3.5, 2.8, 2.7, 2.5, 2.8, 2.3), Wdose = c(30, 32.5, 32.5, 35, 35, 35, 25, 40, 37.5, 37.5, 37.5, 32.5, 37.5, 35, 35, 35, 35, 35, 35, 42.5, 40, 35, 25, 40, 32.5, 35, 32.5, 35, 37.5, 35, 35, 37.5, 37.5, 40, 37.5, 37.5, 40, 40, 40, 40, 37.5, 37.5, 40, 37.5, 40, 40, 32.5, 35, 35, 35, 35), Deldose = c(NA, 2.5, 0, 2.5, 0, 0, -10, 15, -2.7, 0, 0, -5, 5, -2.5, 0, 0, 0, 0, 0, 7.5, -2.5, -5, -10, 15, -7.5, 2.5, -2.5, 2.5, 2.5, -2.5, 0, 2.5, 0, 2.5, -2.5, 0, 2.5, 0, 0, 0, -2.5, 0, 2.5, -2.5, 2.5, 0, -7.5, 2.5, 0, 0, 0)), .Names = c("Date", "Inr", "Wdose", "Deldose"), row.names = c(NA, -51L), class = "data.frame") test_zoo<-zoo(test[,2:3],test[,1]) plot(test_zoo) ## read ?plot.zoo or ?plot.ts plot(test_zoo, plot.type = "single") ## there is a option for plotting both series in one frame ## Secondary y-axis and ticks are a bit tricky and in most cases you have to adjust them by hand plot(test_zoo[,1], ylim=range(pretty(c(0, test_zoo[,1]))), xlab="", ylab="", col="blue") yaxp3<-(par("yaxp")[3]) abline(h=seq(par("yaxp")[1], par("yaxp")[2], (par("yaxp")[2]-par("yaxp")[1])/par("yaxp")[3]), lty=6, col = "grey") par(bty="n", new=T) niceticks<-c(0:(yaxp3)*(pretty(c(0, test_zoo[,2]), n=yaxp3-1)[2]-pretty(c(0, test_zoo[,1]), n=yaxp3-1)[1])) plot(test_zoo[,2], lty=2, yaxt="n", xaxt="n", col="red", ann=FALSE, xlim=c(start(test_zoo),end(test_zoo)), ylim=range(0,max(niceticks))) axis(4, at=niceticks) par(bty="o", new=F) 2014-06-03 15:26 GMT+02:00 John Kane <jrkrid...@inbox.com>: > I know essentially nothing about plotting time series so so I just let it > pass hoping someone with knowledge of time series would help > > What were you expecting to get? Just plotting the time series without > labels etc, since I am getting some weird error messages about pch having a > âunexpected ',' in " pch="16" and I am too lazy to bother debugging it I > get a four panel plot (see attached). This does not seem make any sense to > me since I don't see why Date is plotted, but as I say I know nothing about > time series. > > However the data did come through okay. Presumably test$Date is a date. It > reads in as a factor for me which is one reason for using dput() which > maintains the structure of the data. > > Below is what I think your data looks like in dput() format. > > Sorry not to be of more help. > > test <- structure(list(Date = structure(c(15657, 15664, 15678, 15700, > 15713, 15720, 15734, 15741, 15755, 15769, 15783, 15790, 15811, 15832, > 15839, 15853, 15867, 15880, 15895, 15902, 15916, 15930, 15944, 15951, > 15958, 15965, 15972, 15979, 15986, 16000, 16014, 16021, 16028, 16035, > 16042, 16049, 16056, 16065, 16077, 16084, 16091, 16105, 16112, 16126, > 16141, 16147, 16154, 16161, 16175, 16189, 16203), class = "Date"), Inr = > c(2.2, 2.5, 2.4, 2.3, 2.1, 1.9, 1.9, 3.3, 2.6, 2.7, 3.1, 2.4, 2, 2.5, 2.3, > 2.4, 2.3, 2.3, 2.1, 2.4, 3.6, 3, 1.3, 2.6, 1.9, 3.4, 2.4, 2.2, 2.9, 2.8, > 2.1, 2.2, 2.2, 3, 2.7, 2.3, 2.7, 2.9, 2.7, 2.6, 2.6, 3.3, 2.6, 2.8, 2.9, > 3.5, 2.8, 2.7, 2.5, 2.8, 2.3), Wdose = c(30, 32.5, 32.5, 35, 35, 35, 25, > 40, 37.5, 37.5, 37.5, 32.5, 37.5, 35, 35, 35, 35, 35, 35, 42.5, 40, 35, 25, > 40, 32.5, 35, 32.5, 35, 37.5, 35, 35, 37.5, 37.5, 40, 37.5, 37.5, 40, 40, > 40, 40, 37.5, 37.5, 40, 37.5, 40, 40, 32.5, 35, 35, 35, 35), Deldose = > c(NA, 2.5, 0, 2.5, 0, 0, -10, 15, -2.7, 0, 0, -5, 5, -2.5, 0, 0, 0, 0, 0, > 7.5, -2.5, -5, -10, 15, -7.5, 2.5, -2.5, 2.5, 2.5, -2.5, 0, 2.5, 0, 2.5, > -2.5, 0, 2.5, 0, 0, 0, -2.5, 0, 2.5, -2.5, 2.5, 0, -7.5, 2.5, 0, 0, 0)), > .Names = c("Date", "Inr", "Wdose", "Deldose"), row.names = c(NA, -51L), > class = "data.frame") > > > John Kane > Kingston ON Canada > > -----Original Message----- > From: schmtz...@yahoo.com > Sent: Mon, 2 Jun 2014 08:06:33 -0700 (PDT) > To: jrkrid...@inbox.com, r-help@r-project.org > Subject: Re: [R] Time Series > > John: > > The data that I sent you did you receive it? If so what thoughts or > suggestions do you have for plotting the time series? > > I am not sure what is going wrong and getting multi plot of same. > > Thank you > > Wayne Schlemitz > > schmtz...@yahoo.com > > On Saturday, May 24, 2014 11:34 AM, John Kane <jrkrid...@inbox.com> > wrote: > > No raw data. Sent is as text (csv) or use dput() to include it in the > email. > > John Kane > Kingston ON Canada > > > -----Original Message----- > > From: schmtz...@yahoo.com > > Sent: Fri, 23 May 2014 08:02:31 -0700 (PDT) > > To: r-help@r-project.org > > Subject: [R] Time Series > > > > Dear Sir: > > I am trying to plot a time series from the following code: > > > > test <- read.table("/home/wayne/inr2a.txt", header = TRUE, quote="", sep > > = ";") > > x2 <- ts(data=test, frequency = 80, start = c(2012,11), end = c(2014,5)) > > plot.ts(x2, xlab="Date", ylab="Inr", main="X2 - Time Series", > > ylim=c(1.0,4.0),pch=16, col="black") > > > > What I get is multi plots that print 3x across the plot. > > > > Using R 2.15.2-1 on Ubuntu Natty > > Attached is the raw data. > > > > Thank you for any suggestions. > > Wayne > > ______________________________________________ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help [ > https://stat.ethz.ch/mailman/listinfo/r-help] > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html [ > http://www.r-project.org/posting-guide.html] > > and provide commented, minimal, self-contained, reproducible code. > > ____________________________________________________________ > Protect your computer files with professional cloud backup. > Get PCRx Backup and upload unlimited files automatically. > Learn more at http://backup.pcrx.com/mail [http://backup.pcrx.com/mail] > > ____________________________________________________________ > Protect your computer files with professional cloud backup. > Get PCRx Backup and upload unlimited files automatically. > Learn more at http://backup.pcrx.com/mail > > ______________________________________________ > 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. > > [[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.