[R] Revisiting multiple plots

Gabor Grothendieck ggrothendieck at gmail.com
Sat Mar 17 00:14:08 CET 2007


Try this (or use xyplot.zoo and write a panel function for that):

library(zoo)
set.seed(1)
tt <- as.Date(paste(2004, rep(1:2, 5), sample(28, 10), sep = "-"))
foo <- zoo(matrix(rnorm(100), 10), tt)

pnl <- function(x, y, ...) {
	lines(x, y, ...)
	abline(h = mean(y))
}
plot(foo, panel = pnl)


On 3/16/07, Jonathan Wang <jontwang at gmail.com> wrote:
> Suppose I create a multiple plot with zoo, using:
>
> index <- ISOdatetime(2004, rep(1:2, 5), sample(28, 10), 0, 0, 0)
> foo <- zoo(rnorm(10), index)
> for (i in 1:9) {
>  data <- rnorm(10)
>  z1 <- zoo(data, index)
>  foo <- cbind(foo, z1)
> }
> plot(foo)
>
> This creates 10 plots on one device, one for each column in foo.
>
> Now I want to go back and use abline to draw a line at the mean on each of
> my 10 plots. How do I select the appropriate set of axes to draw my line on?
>
> Thanks,
> Jonathan
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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