ggplot2 for grayscale printouts
ggplot2, r
Solution
** EDIT ** Updated code: `geom_bar` requires a `stat`.
`theme_bw` could be what you're after. If you are plotting a geom that has a fill such as bars, the `scale_fill_grey` function will give you control over the shades of grey. If you are plotting a geom that has a colour (such as a line or points), the `scale_colour_grey` function will give you the control. As far as I know, ggplot does not plot patterned fills. Assuming you're plotting bars, the following will plot coloured bars on a grey background.
library(ggplot2)
data <- read.table(text =
"type Year Value
A 2000 3
B 2000 10
C 2000 11
A 2001 4
B 2001 5
C 2001 12", sep = "", header = TRUE)
(p = ggplot(data = data, aes(x = factor(Year), y = Value)) +
geom_bar(aes(fill = type), stat="identity", position = "dodge"))
The following changes the coloured bars to shades of grey. Note that one of the bars gets lost in the background.
(p = p + scale_fill_grey(start = 0, end = .9))
The following removes the grey background.
(p = p + theme_bw())
A point has a colour, not a fill. So to use shades of grey on points, you would need something like this.
(p = ggplot(data = data, aes(x = factor(Year), y = Value)) +
geom_point(aes(colour = type), size = 5) +
scale_colour_grey(start = 0, end = .9) +
theme_bw())
Problem
ggplot2 produces fancy graphs for screen/color prints, but the gray background and the colors interfere when printing them to grayscale. For better readablility, I'd prefer to disable the gray background and use color generators that produce either different shades of gray or different kinds of filling strokes to distinguish the groups.