【问题标题】:Width parameter and stat = 'identity' in geom_boxplotgeom_boxplot 中的宽度参数和 stat = 'identity'
【发布时间】:2023-03-31 07:31:02
【问题描述】:

我的问题基本上是重复的 Width of boxplot created from summary stats 因为标签不完整(没有 rnor ggplot2 标签)而受到的关注很少,我建议进行相应的修改。

我试图重现示例of this question,我得到了

警告:忽略未知参数:宽度

我觉得这很好奇,因为我之前使用过width 作为参数。删除stat = identity时警告消失了

在很多以前的线程中,这个参数似乎都有效(例如:Fine tuning ggplot2's geom boxplot)。这和升级ggplot2 3.0有关吗?

注意
我真的想要对箱线图使用预先计算的值,我只是在开始回答上述问题时遇到了这个问题。


sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_3.0.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.17     digest_0.6.15    withr_2.1.2      dplyr_0.7.6     
 [5] assertthat_0.2.0 grid_3.5.0       plyr_1.8.4       R6_2.2.2        
 [9] gtable_0.2.0     magrittr_1.5     scales_0.5.0     pillar_1.2.3    
[13] rlang_0.2.2      lazyeval_0.2.1   bindrcpp_0.2.2   labeling_0.3    
[17] tools_3.5.0      glue_1.2.0       purrr_0.2.5      munsell_0.5.0   
[21] yaml_2.1.19      compiler_3.5.0   pkgconfig_2.0.1  colorspace_1.3-2
[25] tidyselect_0.2.4 bindr_0.1.1      tibble_1.4.2  

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    我可以确认这种(奇怪的?)行为。

    例如,如果我们这样做

    ggplot(DF) +
        geom_boxplot(
            aes(x = x, ymin = min, lower = low, middle = mid, upper = top, ymax = max, width = 0.1),
            stat = "identity", fill = "cornflowerblue")
    

    我们收到警告

    警告:忽略未知的美学:宽度

    但它确实改变了宽度

    如果您将width = 0.1 移到aes 之外,则会收到警告,并且宽度不会改变。

    来自相关帖子ggplot - width of boxplot from summary stats [duplicate] 的评论表明情况并非总是如此。


    样本数据

    DF <- data.frame(
        x = c("2012","2016"),
        min = c(29.9,37.0),
        low = c(64.0,58.0),
        mid = c(108.0,73.0),
        top = c(168.0,108.0),
        max = c(258.0,199.0))
    

    【讨论】:

    • 有趣 - 我没想过将width 放入aes 通话中。与此同时,我找到了几个小时前发布的this issue report on GitHub。有趣的是,事情是如何重合的……
    • @Tjebo 有趣的发现。基于较旧的SO post,我认为width 在某些时候确实按预期工作。我看到了您对 GH 问题的评论(顺便说一句,您得到了正确的 ping,谢谢;-)。很想听听开发人员怎么说。
    猜你喜欢
    • 2015-07-16
    • 1970-01-01
    • 2023-02-08
    • 1970-01-01
    • 2019-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-19
    相关资源
    最近更新 更多