** 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())
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…