2

I wish to change the title and labels of a legend in geom_col plot in .

I have tried to use the functions below to change the legend title, however nothing happens:

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

I have also tried to use to change legend title and labels:

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

However then the plot column changes color and I receive the following error message:

Scale for 'fill' is already present. Adding another scale for 'fill', which will replace the existing scale.

My code looks like this:

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"))
massisenergy
  • 1,764
  • 3
  • 14
  • 25
Tiptop
  • 533
  • 5
  • 19

0 Answers0