[R] lattice : using both strip and strip.left
baptiste auguie
ba208 at exeter.ac.uk
Mon Aug 25 13:47:20 CEST 2008
Dear all,
I'm routinely using lattice and ggplot2, I wish to create a lattice
theme that looks not too dissimilar to ggplot's defaults so I can
include both graphs in a document with a consistent look.
To illustrate my questions, consider the following example:
> library(ggplot2)
> library(lattice)
>
> # example data
> x <- seq(0, 10, len = 100)
> y1 <- jitter(sin(x), 1000)
> y2 <- 0.5*jitter(cos(x), 1000)
>
> df <- melt( data.frame(x=x, one=y1, two=y2, condition1=factor(c("a",
> "b")), condition2=factor(c("1","1", "2", "2"))),
> id=c("x", "condition1", "condition2"))
>
> # custom colors
> myColors <- c( "#E41A1C", "#377EB8")
>
> # here is the ggplot2 version
> p <- qplot(x,value, data=df, facets = condition1 ~ condition2,
> colour=variable)
> p <- p + scale_colour_manual(values = myColors)
> print(p)
>
> # lattice version
> lattice.options(default.theme = canonical.theme(color = T))
> trellis.par.set("strip.border" = list(col="white"))
> trellis.par.set("background" = list(col="white"))
> trellis.par.set("axis.line" = list(col="darkgrey"))
> trellis.par.set("strip.background" = list(col="darkgrey"))
> trellis.par.set("plot.symbol" = list(col = myColors, pch=16, cex=0.8))
>
>
> p2 <- xyplot(value ~ x | condition1 + condition2, data=df, groups =
> variable,
> strip=strip.custom(which.given=1),
> strip.left=strip.custom(which.given=2) ,
> panel = function(x, y, ...) {
> panel.fill(grey(0.95), border="white")
> panel.grid(h=-1, v=-1, col="white", col.line="white", lty=1,
> lwd=2.5)
> lpoints(x, y, pch=16, col=1:2, cex=1)
> },
> key = simpleKey(levels(df$variable), space = "right"))
>
> print(p2)
Several things resist me, I welcome any input,
- with two levels of facetting, i often find convenient to layout the
graphs in a 2d, rectangular matrix, and have vertical and horizontal
strips as in ggplot2. Using strip and strip.left as in the example
above leaves some blanks where the other strip is expected. Can this
be tuned?
- in addition to the main grid, I'd like to set a finer, secondary
grid, that subdivides it in halves. I can't find how to do this using
panel.grid
- the axes should be white, but trellis.par.set("axis.line" =
list(col="white")) removes the tick marks altogether. Is there a way
to get rid off the line but keep the tick marks? There is a new
setting for this in base graphics, I guess there must be one in
lattice with an appropriate call to grid?
- to clip the background color to the plotting region as opposed to
the whole page, I use panel.fill, maybe there's a better way (a
setting outside the plotting function)?
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