我使用以下代码生成多个箱图,按变量的平均值排序:
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)
当我将代码更改为horizontal = TRUE
时,我无法将这些点与箱形图对齐。有关如何将points
正确添加到水平箱图的任何想法吗?
答案 0 :(得分:2)
您需要同时给出x和y坐标:
points(zx_means[order (zx_means)], seq_along(zx_means),
pch = 22, col = "darkgrey", lwd = 7)
或
points(zx_means, order (zx_means), pch = 22, col = "darkgrey", lwd = 7)