我使用以下代码生成多个箱线图,按变量的平均值排序:
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
时,我无法使这些点与箱线图对齐。关于如何将点
正确添加到水平箱线图的任何想法?
最佳答案
您需要同时提供 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)
关于r - 向水平箱线图添加点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9874512/