[英]ggplot2: How to adjust fill colour in a boxplot (and change legend text)?
How can I: 我怎样才能:
Change the legend text from "0", "1" to something else? 将图例文本从“0”,“1”更改为其他内容?
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"))
The ggplot2 website help page for scale_manual is full of good examples. 对于GGPLOT2网站帮助页面scale_manual是满不错的例子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.