0

I have made a graph in R using gggplot, and it looks like this:

enter image description here

My problem is that I would like to move the legend items so that "highly agree" appears to the left and "highly disagree" to the right, so that it fits better with the order in the graph. When I google this problem, all solutions that I've tried ends up also changing the order in the graph, but I only want to change the legend. I also want to keep the colors, ie I want "Highly agree" to stay dark green. I realize it's tricky to help me without a mock data set, but I hope someone can help me to at least point to a possible solution without it. If it helps, this is my ggplot code:

 ggplot () +
  geom_bar(aes(x = reorder(Statement, n), y=n, fill=response), position = "fill", stat = "identity") +
  coord_flip() + 
  scale_fill_brewer(palette="PRGn")+
  theme(legend.position="bottom", axis.title.y = element_blank(), legend.title=element_blank(), axis.title.x = element_blank()) +
  scale_y_continuous(labels = percent) 
Norasy
  • 13
  • 3
  • 1
    Have you tried reordering your response variable levels before plotting? `df$response <- factor(df$response, levels=c("Highly agree", "Agree", "Neutral", "Disagree", "Highly disagree"))` then plot – Yacine Hajji Aug 19 '22 at 08:53
  • 2
    To reverse the order in the gudie you could also try `+guides(fill = guide_legend(reverse = TRUE))` – stefan Aug 19 '22 at 09:09

0 Answers0