[R] lattice: add vertical lines in xyplot
baptiste auguie
ba208 at exeter.ac.uk
Thu Aug 7 20:54:06 CEST 2008
Hi list,
This is a very basic question about lattice: I wish to add some
vertical lines in each panel of a xyplot as demonstrated in this
example:
> library(lattice)
>
> xx <- seq(1, 10, length=100)
> x <- rep(xx, 4)
> y <- c(cos(xx), sin(xx), xx, xx^2/10)
> fact <- factor(rep(c("cos", "sin", "id", "square"), each=100))
> fact2 <- factor(rep(c("periodic", "not periodic"), each=100))
>
> my.df <- data.frame(x=x, y=y, fact = fact, fact2 = fact2)
>
> head(my.df)
>
> xyplot(y~x | fact, data = my.df, groups= fact2) # this plots as
> expected
>
> my.lines <- c(5, 6) # i want to draw these vertical lines, according
> to the level of fact2
>
> xyplot(y~x | fact, data = my.df, groups= fact2,
> panel=function(x, y,subscripts, ...) {
> panel.xyplot(x, y,subscripts, ...)
> panel.abline(v=my.lines[subscripts])}
> )
this gives me an error, but I don't understand the help for the panel
function.
Alternatively, I tried in ggplot but here again, I get an error:
> p <- ggplot(my.df, aes(x, y)) +
> geom_path(aes(colour = fact)) +
> facet_grid(fact2 ~ fact) +
> geom_vline(intercept = my.lines) # how do I select the relevant
> one ?
> p
Many thanks,
baptiste
_____________________________
Baptiste Auguié
School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK
Phone: +44 1392 264187
http://newton.ex.ac.uk/research/emag
More information about the R-help
mailing list