I would like to order a ggplot on Rstudio based on the highest value of two columns (Ex. M1 and M2 below). In the example below, the correct order would be Chemical C, B, A, E, D.
Name Parent M1 M2
Chemical A 0.088 0.237 0.310
Chemical B 0.004 0.315 0.238
Chemical C 0.026 0.387 0.285
Chemical D 0.015 0.235 0.272
Chemical E 0.086 0.288 0.272
The code I have been using is:
ggplot(datafile, aes (reorder (x=Name, M1), M1)) + geom_point(aes (y= Parent, color = "black")) + geom_point(aes(y=M1, color = "blue")) + geom_point(aes(y=M2, color = "orange"))
This code successfully orders my data based on M1 values only, but I would like it to order it based on both M1 and M2. How can I modify this code to achieve that?
Thank you!
reorder(x = Name, M1)
withreorder(x = Name, pmax(M1, M2))
. – Gregor Thomas