3

I use the following code to produce multiple boxplots, ranked by the mean value of the variables:

zx <- replicate (5, rnorm(50))
zx_means <- (colMeans(zx, na.rm = TRUE))
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)

(See this post for more details)

When I change the code to horizontal = TRUE, I'm not able to make the points line up with the boxplots. Any ideas for how to properly add points to horizontal boxplots?

Community
  • 1
  • 1
kribys
  • 65
  • 2
  • 8

1 Answers1

4

You need to give both x and y coordinates:

points(zx_means[order (zx_means)], seq_along(zx_means), 
       pch = 22, col = "darkgrey", lwd = 7)

or

points(zx_means, order (zx_means), pch = 22, col = "darkgrey", lwd = 7)
joran
  • 169,992
  • 32
  • 429
  • 468
cbeleites unhappy with SX
  • 13,717
  • 5
  • 45
  • 57