在geom_col ggplot2

时间:2019-06-28 09:51:25

标签: legend geom-col

我希望更改geom_col图中图例的标题和标签。

我尝试使用下面的函数来更改图例标题,但是什么也没发生:

labs(color = "Treatment")
labs(fill = "Treatment")

我还尝试过使用图例标题和标签进行更改:

scale_fill_discrete(name = "Treatment", labels = c("Control", 
"Fertilization", "Shading", "Warming))

然而,绘图列会更改颜色,并且我收到以下错误消息:“'填充'的比例已经存在。为'填充'添加另一个比例,它将替换现有比例。”

我的代码如下:

bar.plot.selected.groups <- ggplot(mean_emission_p12_gr3, aes (x = date, y = 
avg_emission, fill = Treatment)) + geom_errorbar(aes(ymin = avg_emission - 
se, ymax = avg_emission + se), width = 0.5, position = position_dodge(width 
= 0.65)) + geom_col (position = "dodge", width=0.65) + theme(axis.text.x = 
element_text(size = 10, angle = 90, hjust=0, vjust = 0.5), axis.title = 
element_text(size = 14))

bar.plot.selected.groups + labs(x = "Date", y = "Emission rate (µg m-2 h- 
1)", color = treatment) + ggtitle("BVOC emission 2012") + theme(plot.title = 
element_text(size = 20, hjust = 0.5)) + facet_wrap(~ compound_gr_3, scales = 
"free") +  theme(strip.text.x = element_text(size = 12, color = "black", 
face = "bold")) + scale_fill_manual("legend", values = c("C" = "black", "F" 
= "green", "S" = "blue", "W" = "red"))

0 个答案:

没有答案