The default theme on my installation is something which maps the values to pink and cyan. How to change it for example to a gray scale theme?
There are many ways to accomplish your request. The simplest is:
trellis.device(color = FALSE)
another is
ltheme <- canonical.theme(color = FALSE) ## in-built B&W theme
ltheme$strip.background$col <- "transparent" ## change strip bg
lattice.options(default.theme = ltheme) ## set as default
See http://www.mail-archive.com/[email protected]/msg64699.html and http://tolstoy.newcastle.edu.au/R/e2/help/07/07/22317.html for more info.
You can use
library(lattice)
lattice.options(default.theme = standard.theme(color = FALSE))
which turns on black-and-white suitable for printing. I've also played with things like
sb <- trellis.par.get("strip.background")
sb[["col"]][1] <- "lightgray"
trellis.par.set("strip.background", sb)
which changes just the header background.
And I thought people only asked ggplot2 questions here :) Nice to see some lattice for a change.
Thanks for the answers guys! It also helped me to find more information on the subject. I learned that I can control the scales of gray using for example the following:
levelplot(my_var, col.regions = gray(0:100/100))
which gives me 100 shades of gray from black (0) to white (1).
I'm using the function to plot gray scale images (photos) which I've pre-processed to a double matrix. I don't know if it's the best possible approach, but so far it works and I believe it gives me more options for graphing than the basic displaying options in the EBImage and rimage libraries. I don't know how I'd alter the palette to match displaying color images, but I'm glad I didn't have to do that so far...
You may also want to consider using panel.levelplot.raster
, as it reduces the figure size sizably, as I recently found out. Combining this tip with changing trellis settings in general, here are a following examples:
trellis.par.set(regions=list(col=topo.colors(100)))
levelplot(volcano, panel = panel.levelplot.raster)
levelplot(volcano, panel = panel.levelplot.raster,
par.settings=list(regions=list(col=topo.colors(100))))
The second method is deceptive because the trellis settings are in fact being changed globally. I didn't know about the col.regions argument though - that's pretty nice as it seems to change the color theme locally.