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() 
3
  • 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 including a snippet of your data or some fake data. Commented Jul 13, 2022 at 10:08
  • 2
    Ggplot2 orders strings alphabetically. If you want them ordered differently, make them factors, 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.) Commented Jul 13, 2022 at 10:52
  • Does this answer your question? How do I set factor levels to the order they appear in a data frame? Commented Jul 13, 2022 at 16:27

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.