0

I am attempting to plot a bubble plot using the geom_point function in ggplot2. The y values represent a comparison of differentially expressed genes between two tissue types, but there are two comparisons for each two tissue types, each going the opposite way e.g. for a comparison between aortic endothelium and haemogenic endothelium I have two comparisons: AEvsHE and HEvsAE.I would like these two comparisons to be next to eachother on the plot but that is not how ggplot2 has ordered them.

Is there a way to 'override' the algorithm that R uses and order the y values manually?

Here is my code so far:

ggplot(cl,aes(y=DEG,x=comparison, size=enrichment))+
    geom_point(alpha=0.5)+scale_size(range=c(1,5), name="enrichment")+
    theme_bw()
stefan
  • 90,330
  • 6
  • 25
  • 51
  • 3
    Welcome to SO! The answer is probably yes. But from the provided information it's hard to come up with a working solution, i.e. it would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. – stefan Jul 13 '22 at 10:08
  • 2
    Ggplot2 orders strings alphabetically. If you want them ordered differently, make them `factor`s, controlling the order of their `levels=`. (If you search SO for `ggplot2 axis factor levels`, you will likely find many good examples to help you with this.) – r2evans Jul 13 '22 at 10:52
  • Does this answer your question? [How do I set factor levels to the order they appear in a data frame?](https://stackoverflow.com/questions/26469612/how-do-i-set-factor-levels-to-the-order-they-appear-in-a-data-frame) – Michael Roswell Jul 13 '22 at 16:27

0 Answers0