ggplot2:如何调整boxplot中的填充颜色(和更改图例文本)? [英] ggplot2: How to adjust fill colour in a boxplot (and change legend text)?
本文介绍了ggplot2:如何调整boxplot中的填充颜色(和更改图例文本)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何能:
How can I:
- 在下面的boxplot中设置填充颜色?
-
将图例文本从0,1更改为其他内容?
- Set the fill colors in the boxplot below? I tried the argument "colour" but that failed.
Change the legend text from "0", "1" to something else?
require(ggplot2)
ggplot(mtcars, aes(factor(cyl), mpg)) +
geom_boxplot(aes(fill=factor(vs), colour=c("grey50", "white")))
推荐答案
不是色彩美学,而是要调整填充美学。您可以通过调整比例来处理您的两个问题(以及更多):
Instead of the colour aesthetic, you want to adjust the fill aesthetic. You can handle both of your questions (and much more) by adjusting the scale:
ggplot(mtcars, aes(factor(cyl), mpg, fill = factor(vs))) +
geom_boxplot() +
scale_fill_manual(name = "This is my title", values = c("pink", "green")
, labels = c("0" = "Foo", "1" = "Bar"))
scale_manual 的ggplot2网站帮助页面充满了很好的例子。
The ggplot2 website help page for scale_manual is full of good examples.
这篇关于ggplot2:如何调整boxplot中的填充颜色(和更改图例文本)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文