添加点水平盒状图水平、盒状图

2023-09-11 07:33:59 作者:美丽式遗憾丶

我用下面的code产生多个箱图,通过变量的平均值排名:

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)

(看到这个职位的更多详细信息)

当我改变code到水平= TRUE ,我不能做出点排队的盒状图。任何想法如何正确添加来横向箱线图?

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?

推荐答案

您需要给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)