Search code examples
rlattice

How to make lattice xyplot() grayscale in R?


What is the simplest way to make just this plot grayscale (or perhaps black and white) rather than the default multi-colour:

xyplot(y1 + y2 ~ x, mydata, auto.key=TRUE)

I've seen discussion of creating new graphics devices or changing options for all plots, but is there an option that I can include perhaps in the xyplot() function itself that will convert the plot to grayscale?


Solution

  • library(lattice)
    bwtheme <- standard.theme("pdf", color=FALSE)
    mydata <- data.frame(y1=rnorm(10), y2=rnorm(10), x=1:10)
    xyplot(y1 + y2 ~ x, mydata, auto.key=TRUE, par.settings=bwtheme)
    

    For comparison:

    comparison of color vs black/white