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?
5 Answers
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.

- 360,940
- 56
- 644
- 725
-
1indeed, with enough effort one may convince lattice to produce plots that have [little to envy to ggplot2's polished looks](http://latticeextra.r-forge.r-project.org/#layer&theme=ggplot2like). There's no latticelike theme for ggplot2 that I know of. – baptiste Jul 28 '12 at 02:58
-
1This did not work, at least not within org-mode. Had to use `trellis.par.set(canonical.theme(color = FALSE))` – Henrik Sep 26 '12 at 12:23
-
@Henrik Same for me - thanks for sharing your solution! – deca Feb 04 '18 at 19:11
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...

- 1,099
- 3
- 12
- 13
-
If you have 256 levels of gray in your image (8bit), maybe gray(0:255/255) would be closer to the original? – Greg Sep 14 '10 at 23:39
-
Hey, a good tip! Although in the case of my images I stop seeing differences with values up from 50. – user442446 Sep 15 '10 at 10:15
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 this mail archive item: Re: [R] specify lattice black-and-white theme for more info.

- 17,193
- 6
- 67
- 97

- 11,564
- 5
- 41
- 27
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.

- 42,883
- 45
- 137
- 231