【问题标题】:How to draw a ggplot2 boxplot with precalculated stats in R?如何在 R 中使用预先计算的统计数据绘制 ggplot2 箱线图?
【发布时间】:2015-03-16 19:00:36
【问题描述】:

我正在尝试获取预先计算的数据集的箱线图。数据集已经包含我运行的响应时间测试的最小值、最大值、中值、第 10 个百分位和第 90 个百分位。无论如何要从中产生一个ggplot2箱线图吗?

我已经包含了一个日期集示例。

谢谢,

throughput <- c(1, 2, 3, 4, 5)
response_time_min <- c(9, 19, 29, 39, 49)
response_time_10  <- c(50, 55, 60, 60, 61)
response_time_med <- c(100, 100, 100, 100, 100)
response_time_90  <- c(201, 201, 250, 200, 230)
response_time_max <- c(401, 414, 309, 402, 311)
df <- data.frame(throughput, response_time_min, response_time_10, response_time_med, response_time_90, response_time_max)
df
throughput response_time_min response_time_10 response_time_med response_time_90 response_time_max
1          1                 9               50               100              201               401
2          2                19               55               100              201               414
3          3                29               60               100              250               309
4          4                39               60               100              200               402
5          5                49               61               100              230               311

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    是的。在official documentation 中搜索“precomputed stat”。

    library(ggplot2)
    ggplot(df) +
    geom_boxplot(aes(x=factor(throughput),
                     ymax = response_time_max,
                     upper = response_time_90,
                     y = response_time_med,
                     middle = response_time_med, 
                     lower = response_time_10, 
                     ymin = response_time_min), stat = "identity")
    

    【讨论】:

      猜你喜欢
      • 2014-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-13
      相关资源
      最近更新 更多