Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boxplots ranked by mean value

Tags:

r

ggplot2

boxplot

I would like to show boxplots for multiple variables, and rank them by column means in descending order, just like in the Performance Analytics package. I use the following code to generate the boxplots:

zx <- replicate (5, rnorm(50))
zx_means <- (colMeans(zx, na.rm = TRUE))
boxplot(zx, horizontal = FALSE, outline = FALSE)
points(zx_means, pch = 22, col = "darkgrey", lwd = 7)

So far I have not been able to come up with a way to rank them as described above. I have tried using both sort and order, but without any satisfying results so far.

Any help would be much appreciated.

like image 986
kribys Avatar asked Dec 14 '25 16:12

kribys


1 Answers

order works fine for me!?:

colnames (zx) <- seq_len (ncol (zx))
boxplot(zx [, order (zx_means)], horizontal = FALSE, outline = FALSE)
points(zx_means [ order (zx_means)], pch = 22, col = "darkgrey", lwd = 7)
like image 165
cbeleites unhappy with SX Avatar answered Dec 16 '25 10:12

cbeleites unhappy with SX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!