I have some code to plot boxplots for 150 variables, each with 3 replicates. This works no problem, but I want to reorder them so they appear from lowest mean to highest mean along the x-axis. Any suggestions on what I can use to do this?
Asked
Active
Viewed 27 times
-2
-
If you are using the `tidyverse`, have a look at `fct_reorder`. – Andrew Gustar May 20 '21 at 15:41
-
1[See here](https://stackoverflow.com/q/5963269/5325862) on making a reproducible example that is easier for folks to help with. We'd only be able to give vague suggestions without seeing data and code. Also take a look again at [ask] – camille May 20 '21 at 15:47
1 Answers
0
You can order the variables according to their mean value by just writing:
ordered.names = names(df)[order(colMeans(df))]
Then, you'll know the order in which you have to draw them and can use this order in the loop you use to draw the plots or to reorder the data.frame itself (df = df[,ordered.names])
)

Martin Wettstein
- 2,771
- 2
- 9
- 15