How can I descending reorder the dots in the scatter plot in ggplot based on the X values ?
2
0
Entering edit mode
19 months ago
mohsamir2016 ▴ 30

Dear All, I am stuck at one trick in ggplot in R: I am trying to plot a scatter plot for metabolites (y axis) based on their VIP score (X axis) here is the data Data, but when I run this in ggplot, it produced non-ordered scattering of the points as you can see here enter image description here I would like to plot the same figure but with the dots being descending order from high to low similar to this one Wanted plot

I have tried using reorder but could not get my head around it. Here is my script

ggplot(VIP, aes(x= `Mean decrease in model accuracy`, y = Metabolites, color = Class)) + geom_point(size = 3) 

HIghly appreciating for any help

Thanks

RNA seq • 795 views
ADD COMMENT
0
Entering edit mode
19 months ago
iraun 6.2k

You can give a try to forcats. For example, you could try first to sort your dataframe by in descending order based on the score, and then force ggplot to plot in order of appearance in the dataframe with fct_inorder():

ggplot(VIP.... y = fct_inorder(Metabolites))
ADD COMMENT

Login before adding your answer.

Traffic: 1505 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6