R:改变堆积条形图的颜色 [英] R: changing color of stacked barplot
本文介绍了R:改变堆积条形图的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
library(ggplot2)
df2 <- data.frame(supp=rep(c("VC", "OJ"), each=3),
dose=rep(c("D0.5", "D1", "D2"),2),
len=c(6.8, 15, 33, 4.2, 10, 29.5))
head(df2)
ggplot(data=df2, aes(x=dose, y=len, fill=supp)) +
geom_bar(stat="identity")
我有一个简单的堆叠式barplot,我想手动更改颜色.更具体地说,我想翻转用于fill = supp
的颜色(即,用青绿色代替OJ).我试过在geom_bar
中添加一个color = ...
参数,但这只是勾勒出条形图而不是给它们上色.
I have a simple stacked barplot, and I would like to change the colors manually. More specifically, I would like to flip the colors used for fill = supp
(i.e. teal for OJ instead). I've trid adding a color = ...
parameter into geom_bar
but that simply outlines the barplots instead of coloring them in.
推荐答案
ggplot(data=df2, aes(x=dose, y=len, fill=supp)) +
geom_bar(stat="identity")+scale_fill_manual(values = c("Green","tomato"))
这篇关于R:改变堆积条形图的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文