0

enter image description here

ggplot() + 
  geom_bar(data = plotDf,
           aes(x = reorder(plotDf$sample_id), y = counts, fill = condition), 
           stat = 'identity') + 
labs(x = 'Sample') + 
theme_bw() +
theme(axis.text.x = element_text(angle = 90))+ 
scale_fill_manual (values = cbPalette)

Hello everyone,

The above is my code and barplot. I would like to change the order of sample and legend to 'wt''wt_dia''wt_afn', 'wt_2mut', 'wt_1mut' , which is same as in my dataframe(plotDf). but here apparently, the order is shown in an alphabetical manner. Thanks very much!

Richard Telford
  • 9,558
  • 6
  • 38
  • 51
Tona
  • 1
  • Make your variable into a factor with the levels in the correct order. Do this outside of the ggplot – Richard Telford Mar 23 '20 at 11:49
  • 1
    Does this answer your question? [How to reorder a legend in ggplot2?](https://stackoverflow.com/questions/26872905/how-to-reorder-a-legend-in-ggplot2) – tjebo Mar 23 '20 at 11:51
  • in addition, please have a look at this thread: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – tjebo Mar 23 '20 at 11:51

0 Answers0