使用ggplot2建议黑白配色方案

时间:2011-05-12 16:56:55

标签: r ggplot2

我正在使用ggplot2来生成许多这样的结构图:

enter image description here

是否容易生产出黑白相似的东西?我确实读过这个question,但它仍然会产生彩色填充。

2 个答案:

答案 0 :(得分:32)

我不确定颜色是否真的有助于此图表,因为已经清楚每个箱图对应的内容。但是,如果您仍然需要使用黑白两色进行着色,则可以使用scale_fill_grey来实现。这是一个例子

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

这将产生如下所示的输出 enter image description here

答案 1 :(得分:9)

ggplot的默认fill颜色为黑白:

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

enter image description here

如果您不想使用灰度面板,可以使用黑白主题:

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

enter image description here

要获得颜色或灰度fill作为比例,您必须将填充作为参数添加到aes(如@ramnath所示)。

相关问题