【问题标题】:How can I use jitter horizontally on boxplot outliers?如何在箱线图异常值上水平使用抖动?
【发布时间】:2018-08-27 07:28:37
【问题描述】:

我从Outliers for boxplot 尝试了以下方法,效果很好:

bar <- boxplot(foo,plot=FALSE)
boxplot(foo,outline=FALSE,ylim=c(min(c(bar$stats,bar$out)),max(c(bar$stats,bar$out))))
points(jitter(rep(1, length(bar$out))), bar$out)

我需要做的是将它与箱线图参数水平 = TRUE 一起使用。 我的箱线图确实可以水平工作,但不存在抖动的异常值。

关于如何完成这项工作的任何建议? 提前致谢。

【问题讨论】:

    标签: r boxplot


    【解决方案1】:

    您只需将xy 参数更改为points()。还要注意我是如何简化ylim的。

    set.seed(12345)
    foo <- rnorm(1000)
    bar <- boxplot(foo, plot = FALSE)
    boxplot(foo, outline = FALSE,
            ylim = range(foo),
            horizontal = TRUE)
    points(bar$out, jitter(rep(1, length(bar$out))))
    

    【讨论】:

      【解决方案2】:

      在多组设置中,以下工作:

      p <- boxplot(
          Sepal.Width ~ Species,
          data = iris,
          range = 0.5, # Just to get more outliers to show
          outline = FALSE,
          ylim = range(iris$Sepal.Width)
      )
      points(jitter(p$group, 0.1), p$out)
      

      reprex package (v2.0.1) 于 2022-02-14 创建

      注意使用 p$group 来获取异常值的 x 坐标(而不是之前的答案中的 rep)。

      【讨论】:

        猜你喜欢
        • 2020-08-21
        • 1970-01-01
        • 2021-09-23
        • 2020-05-04
        • 2018-07-02
        • 1970-01-01
        • 2023-03-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多