r - 向水平箱线图添加点

标签 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 )

当我将代码更改为 horizo​​ntal = 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/

相关文章:

r - 如何旋转/取消旋转(类型转换/熔化)数据框?

r - 计算 R 中两个事件(给定日期和时间)之间的时间差

html - 我如何在一行中证明这三个 div,一个在左边,一个在中间,一个在右边?

python - 从 Pandas 时间序列生成星期几箱线图的最佳方法

r - 使用ggplot2合并并完美对齐直方图和Boxplot

r - R中轴刻度线与相应标签之间的距离

R:将数据框转换为表

css - 如何对齐表格单元格中的文本?

ios - 如何垂直居中 UITextField 文本?

python - 箱线图网格