Hello, I want to plot a time series and add lines to the plot later on. However, this seems to work only as long as I plot the series against the default index. As soon as I plot against an object of class chron or POSIXt (i.e. I want to add a date/time axis), the lines do not appear anymore. The command to add the lines is executed without an error message. (THIS DOES NOT ADD THE LINES) plot(datum2[(3653):(3653+i)],dlindus[(3653):(3653+i)], col =hcl(h=60,c=35,l=60), ylim=c(-8,8), type = "l", xlab=(""), ylab=("Return"), main = ("Industry")) lines(gvarindus, type="l", lwd=2) lines(quantindustlow, col ="black", type = "l",lty=3) lines(quantindusthigh, col ="black", type = "l",lty=3) (THIS ADDS THE LINES, but then I dont have an date axis) plot(dlindus[(3653):(3653+i)], col =hcl(h=60,c=35,l=60), ylim=c(-8,8), type = "l", xlab=(""), ylab=("Return"), main = ("Industry")) lines(gvarindus, type="l", lwd=2) lines(quantindustlow, col ="black", type = "l",lty=3) lines(quantindusthigh, col ="black", type = "l",lty=3) This sounds like a fairly simple problem, but I cannot find any answer in the R-help archives. Thanks alot. Zeno
On Tue, 7 Aug 2007, Zeno Adams wrote:> > Hello, > > I want to plot a time series and add lines to the plot later on. > However, this seems to work only as long as I plot the series against > the default index. As soon as I plot against an object > of class chron or POSIXt (i.e. I want to add a date/time axis), the > lines do not appear anymore. The command to add the lines is executed > without an error message.1. Read the posting guide! 2. Provide a reproducible example (as suggested in the posting guide). 3. Use a time series object for your time series, see e.g. package "zoo". If you set up a multivariate time series, you can get what you want by plot(z, plot.type = "single") See the "zoo" vignettes for more information. 4. If you really want to modify the code below, you probably need to repeat (the right elements of) datum2 in lines(), e.g., lines(datum2[...], gvarindus, lwd = 2) and you should really drop unnecessary brackets as in ylab = ("Return") hth, Z> (THIS DOES NOT ADD THE LINES) > plot(datum2[(3653):(3653+i)],dlindus[(3653):(3653+i)], col > =hcl(h=60,c=35,l=60), ylim=c(-8,8), type = "l", xlab=(""), > ylab=("Return"), main = ("Industry")) > lines(gvarindus, type="l", lwd=2) > lines(quantindustlow, col ="black", type = "l",lty=3) > lines(quantindusthigh, col ="black", type = "l",lty=3) > > (THIS ADDS THE LINES, but then I dont have an date axis) > plot(dlindus[(3653):(3653+i)], col =hcl(h=60,c=35,l=60), ylim=c(-8,8), > type = "l", xlab=(""), ylab=("Return"), main = ("Industry")) > lines(gvarindus, type="l", lwd=2) > lines(quantindustlow, col ="black", type = "l",lty=3) > lines(quantindusthigh, col ="black", type = "l",lty=3) > > This sounds like a fairly simple problem, but I cannot find any answer > in the R-help archives. > > Thanks alot. > > Zeno > > ______________________________________________ > R-help at stat.math.ethz.ch 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. > >
On Tue, 7 Aug 2007, Zeno Adams wrote:> > Hello, > > I want to plot a time series and add lines to the plot later on. > However, this seems to work only as long as I plot the series against > the default index. As soon as I plot against an object > of class chron or POSIXt (i.e. I want to add a date/time axis), the > lines do not appear anymore. The command to add the lines is executed > without an error message. > > (THIS DOES NOT ADD THE LINES) > plot(datum2[(3653):(3653+i)],dlindus[(3653):(3653+i)], col > =hcl(h=60,c=35,l=60), ylim=c(-8,8), type = "l", xlab=(""), > ylab=("Return"), main = ("Industry")) > lines(gvarindus, type="l", lwd=2) > lines(quantindustlow, col ="black", type = "l",lty=3) > lines(quantindusthigh, col ="black", type = "l",lty=3) > > (THIS ADDS THE LINES, but then I dont have an date axis) > plot(dlindus[(3653):(3653+i)], col =hcl(h=60,c=35,l=60), ylim=c(-8,8), > type = "l", xlab=(""), ylab=("Return"), main = ("Industry")) > lines(gvarindus, type="l", lwd=2) > lines(quantindustlow, col ="black", type = "l",lty=3) > lines(quantindusthigh, col ="black", type = "l",lty=3) > > This sounds like a fairly simple problem, but I cannot find any answer > in the R-help archives.Look at the help for lines: the standard call is lines(x, y, col ="black", type = "l",lty=3) and you have omitted x. See ?xy.coords for what happens then. I think the reason you did not find this in the archives is that this is a rare misreading (or non-reading) of the help pages. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595