将点添加到水平箱图

时间:2012-03-26 14:57:16

标签: r alignment boxplot

我使用以下代码生成多个箱图,按变量的平均值排序:

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正确添加到水平箱图的任何想法吗?

1 个答案:

答案 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)