我有以下条形图,但是我只能更改边框的颜色。不管我尝试了什么,我都无法更改显示为灰色的Barplot内部的颜色。
pteddf=data.frame(x=c(0:12),runif(13),runif(13))
tidyr::pivot_longer(pteddf, -x)
colors=c("red", "blue")
ggplot(tidyr::pivot_longer(pteddf, -x),aes(-x,value,color=name,group=name))+
geom_bar(stat="identity",position=position_dodge())+
scale_color_manual(name="",labels = c("Negative TED","Positive TED"),
values= colors)+
scale_fill_manual( values = colors)
尝试这个。您可以fill
在aes()
部分中使用更改填充的颜色:
pteddf=data.frame(x=c(0:12),runif(13),runif(13))
tidyr::pivot_longer(pteddf, -x)
colors=c("red", "blue")
ggplot(tidyr::pivot_longer(pteddf, -x),aes(-x,value,
fill=name,
color=name,group=name))+
geom_bar(stat="identity",position=position_dodge())+
scale_color_manual(name="",labels = c("Negative TED","Positive TED"),
values= colors)+
scale_fill_manual(name="",values = colors,
labels = c("Negative TED","Positive TED"))
输出:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句