[R] cannot add lines to plot

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Aug 7 11:23:44 CEST 2007


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



More information about the R-help mailing list