23

I'm using ggplot2 to produce many diagrams structured like this:

enter image description here

Is there an easy of producing something that looks good in black and white? I did read this question but it still is producing a colored fill.

Community
  • 1
  • 1
djq
  • 14,810
  • 45
  • 122
  • 157

2 Answers2

36

I am not sure if color really helps in this graph, since it is already clear what each boxplot corresponds to. However, if you still need to color this in black and white, you can achieve it using scale_fill_grey. Here is an example

library(ggplot2)
data(tips)
p0 = qplot(day, tip/total_bill, data = tips, geom = 'boxplot', fill = day) + 
  scale_fill_grey()
print(p0)

This produces the output shown below enter image description here

Ramnath
  • 54,439
  • 16
  • 125
  • 152
  • 13
    You may want to use theme_bw() in this case as well, to bring out the gray contrast a bit better. Also, check out ?scale_colour_brewer() for colour palettes that will degrade gracefully in B&W. And don't forget to reorder your factor into an order that makes sense ... – Ben Bolker May 12 '11 at 18:43
  • What I meant about colorBrewer is in the answer to the question referred to above: http://stackoverflow.com/questions/2895319/how-to-add-texture-to-fill-colors-in-ggplot2/3011030#3011030 . It will produce colour fills, but ones that should robust to translation to grayscale. – Ben Bolker May 12 '11 at 19:40
  • Thanks - part of my reason for using color, is that it is shown with a related map. The b/w colors you describe should do the job! – djq May 12 '11 at 20:46
9

The default fill colour for ggplot is black and white:

ggplot(diamonds, aes(x=cut, y=price, group=cut)) + geom_boxplot()

enter image description here

If you prefer not to have the greyscale panel, you can use the black and white theme:

ggplot(diamonds, aes(x=cut, y=price, group=cut)) + geom_boxplot() + theme_bw()

enter image description here

To get a colour or greyscale fill as a scale you have to add fill as a parameter to aes (as illustrated by @ramnath).

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
Andrie
  • 176,377
  • 47
  • 447
  • 496