[R] lattice grayscale "theme"

Deepayan Sarkar deepayan.sarkar at gmail.com
Tue Jul 31 01:52:07 CEST 2007


On 7/30/07, Patrick Drechsler <patrick at pdrechsler.de> wrote:
> The Gmane interface seems to have some lag at the moment...
>
> "Deepayan Sarkar" <deepayan.sarkar at gmail.com> writes:
>
> > On 7/28/07, Patrick Drechsler <patrick at pdrechsler.de> wrote:
> >>
> >> is there a grayscale setting for lattice plots?
> >>
> >> I like the default color settings. I also like the settings that are
> >> available for setting black and white with something like this:
> >>
> >> --8<---------------cut here---------------start------------->8---
> >> 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
> >> --8<---------------cut here---------------end--------------->8---
> >>
> >> Is there a simple way of achieving something in between these settings
> >> (using grayscales for the default colors)?
> >
> > Possibly, but you would have to define what you mean by 'simple' and
> > 'something in between' more precisely.
>
> Here is an example of 'in between':
>
> --8<---------------cut here---------------start------------->8---
>   ## Set background color of strips to grayscales:
>   strip.background <- trellis.par.get("strip.background")
>   trellis.par.set(strip.background = list(col = grey(7:1/8)))
>   ## Set color of plot symbols to grayscale:
>   plot.symbol <- trellis.par.get("plot.symbol")
>   trellis.par.set(plot.symbol = list(col = grey(5/8)))
> --8<---------------cut here---------------end--------------->8---

Well, there you go. You have a new theme.

> I think it would be nice to have a few default "themes": A single
> switch between "default color", "grayscale" and "black and white".

I'm still not sure what qualities you are looking for in the new
theme. An upcoming version of the latticeExtra package will have a
function that can be used to create a theme based on some given
colors; you might find it useful. It uses colors from RColorBrewer by
default, and looks like:


brewer.theme <-
    function(symbol = brewer.pal(n = 8, name = "Dark2"),
             fill = brewer.pal(n = 12, name = "Set3"),
             region = brewer.pal(n = 11, name = "Spectral"),
             reference = "#e8e8e8",
             bg = "transparent",
             fg = "black")
{
    theme <-
        list(plot.polygon      = list(col = fill[1], border = fg[1]),
             box.rectangle     = list(col= symbol[1]),
             box.umbrella      = list(col= symbol[1]),
             dot.line          = list(col = reference),
             dot.symbol        = list(col = symbol[1]),
             plot.line         = list(col = symbol[1]),
             plot.symbol       = list(col= symbol[1]),
             regions           = list(col = colorRampPalette(region)(100)),
             reference.line    = list(col = reference),
             superpose.line    = list(col = symbol),
             superpose.symbol  = list(col = symbol),
             superpose.polygon = list(col = fill, border = fg),

             background        = list(col = bg),
             add.line          = list(col = fg),
             add.text          = list(col = fg),
             box.dot           = list(col = fg),
             axis.line         = list(col = fg),
             axis.text         = list(col = fg),
             strip.border      = list(col = fg),
             box.3d            = list(col = fg),
             par.xlab.text     = list(col = fg),
             par.ylab.text     = list(col = fg),
             par.zlab.text     = list(col = fg),
             par.main.text     = list(col = fg),
             par.sub.text      = list(col = fg))
    modifyList(standard.theme("pdf"), theme)
}

-Deepayan



More information about the R-help mailing list