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

______________________________________________
R-help@r-project.org 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.

Reply via email to