[R] cannot add lines to plot

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Tue Aug 7 11:01:11 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.

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.
>
>



More information about the R-help mailing list