Main · Black and White in R

This page was last modified on 26 May 2007, at 22:38 NZST

I was creating some trellis plots using R for a student, who wanted everything in black and white. I was playing with the xyplot command, setting options, fixing all the little details (even discovering some data issues in the process). Then, I decided to save them as PDF, when I discovered that, duh!, pdf() always saves everything as colour. Before thinking on saving the files I was using trellis.device(color = FALSE), but it did not make a difference for exporting as PDF.

Looking in the R email lists I found that one has to use trellis.device() after calling pdf() and force it to avoid creating a new canvas. Something like this:

pdf('~/Documents/Research/2007/Algae/temp05degrees.pdf',
     width = 11.7, height = 8.26, pointsize = 9)
trellis.device(new = FALSE, color = FALSE)

# and then the graph
xyplot(percent ~ time | temp:light.level:humidity,
       group = tray,
       type = 'b',
       data = rocks[rocks$temp == 5,],
       xlab = 'Exposure [hours]',
       ylab = 'Percentage live [%]',
       layout = c(4,2))
dev.off()

which works perfectly.

Keywords: , .