0

I have created a mirrored bar chart to compare two variables. I have managed to get each of these a different colour, but haven't had any success with getting a figure legend to explain what each part means. For example, what the top graph means and what the bottom means. Additionally, for another graph I would like to have a legend at the side to give added information about the x axis categories since they do not fit.

This should be pretty simple, but I've tried fill= with no luck. My problem is I am not sure where to put the command in the code since I have effectively combined two separate graphs.

new2 <- mutate(new, Review = -Review)

p2<-ggplot(new2, aes(x = metric)) + geom_col(aes(y = Mine), fill = "lightblue", width=0.3, position=position_dodge(width=0.1)) + geom_col(aes(y = Review), fill = "lightgreen", width=0.3, position=position_dodge(width=0.1)) + xlab("Metric") + ylab("Percentage")

My data looks like this: Data

I would appreciate any thoughts on how I can add a figure legend at the side. I have no problem doing this in standard barcharts.

tjebo
  • 21,977
  • 7
  • 58
  • 94
Anna
  • 1
  • 6
  • 1
    instead of `geom_col(aes(y = Review), fill = "lightgreen")`, write geom_col(aes(y = Review, fill = ...), ...)` Note the different position of the closing bracket. And fill needs to be the column name without quotes which define this aethetic – tjebo Jan 06 '21 at 14:31
  • 1
    @tjebo. Yep. Absolute right. Will do. (: – stefan Jan 06 '21 at 14:35
  • Thanks very much! – Anna Jan 06 '21 at 19:14

0 Answers0