【问题标题】:Increase `emmeans` comparison arrows' thickness增加`emmeans`比较箭头的粗细
【发布时间】:2021-08-18 05:45:00
【问题描述】:

我正在寻找一种巧妙的方法来增加箭头的粗细。我的粗略想法是geom_line(aes(size = 5))。我得到的不是更粗的箭头,而是一个新的传说。

如何更改我的代码?非常感谢。

 warp.lm <- lm(breaks ~ wool * tension, data = warpbreaks)
 warp.emm <- emmeans(warp.lm, ~ tension | wool)
plot(warp.emm, by = NULL, comparisons = TRUE, adjust = "mvt", 
   horizontal = FALSE, colors = c("darkgreen")) +
  geom_line(aes(size = 5))

这段代码,geom_line(arrow(size = 5)) 返回错误:Error in arrow(size = 5) : unused argument (size = 5)

如何更改我的代码?非常感谢。

【问题讨论】:

    标签: r ggplot2 emmeans


    【解决方案1】:

    首先,您是一个图例,因为您映射到 size aes 而不是使用大小作为参数,即在 aes() 之外。其次,您会收到一个错误,因为arrow() 没有大小参数。见?arrow

    相反,您可以像这样增加箭头的大小:

    library(emmeans)
    library(ggplot2)
    warp.lm <- lm(breaks ~ wool * tension, data = warpbreaks)
    warp.emm <- emmeans(warp.lm, ~ tension | wool)
    g <- plot(warp.emm, by = NULL, comparisons = TRUE, adjust = "mvt", 
         horizontal = FALSE, colors = c("darkgreen"))
    
    

    检查 ggplot 对象,我们看到它由五层组成,其中箭头是通过geom_segment 第 3 层和第 4 层绘制的:

    g$layers
    #> [[1]]
    #> geom_point: na.rm = FALSE
    #> stat_identity: na.rm = FALSE
    #> position_identity 
    #> 
    #> [[2]]
    #> mapping: xend = ~ucl, yend = ~pri.fac, x = ~lcl, y = ~pri.fac 
    #> geom_segment: arrow = NULL, arrow.fill = NULL, lineend = butt, linejoin = round, na.rm = FALSE
    #> stat_identity: na.rm = FALSE
    #> position_identity 
    #> 
    #> [[3]]
    #> mapping: xend = ~lcmpl, yend = ~pri.fac, x = ~the.emmean, y = ~pri.fac 
    #> geom_segment: arrow = list(angle = 30, length = 0.07, ends = 2, type = 2), arrow.fill = NULL, lineend = butt, linejoin = round, na.rm = FALSE
    #> stat_identity: na.rm = FALSE
    #> position_identity 
    #> 
    #> [[4]]
    #> mapping: xend = ~rcmpl, yend = ~pri.fac, x = ~the.emmean, y = ~pri.fac 
    #> geom_segment: arrow = list(angle = 30, length = 0.07, ends = 2, type = 2), arrow.fill = NULL, lineend = butt, linejoin = round, na.rm = FALSE
    #> stat_identity: na.rm = FALSE
    #> position_identity 
    #> 
    #> [[5]]
    #> geom_point: na.rm = FALSE
    #> stat_identity: na.rm = FALSE
    #> position_identity
    

    因此,要增加箭头的粗细,您可以像这样设置这些层的size 参数:

    
    g$layers[[3]]$aes_params$size = 1.5
    g$layers[[4]]$aes_params$size = 1.5
    
    g
    

    reprex package (v2.0.0) 于 2021 年 5 月 30 日创建

    【讨论】:

    • 非常感谢您的详细解释。我现在也知道如何修改阴影了。 :)
    猜你喜欢
    • 1970-01-01
    • 2017-01-20
    • 2011-10-19
    • 1970-01-01
    • 2018-02-08
    • 1970-01-01
    • 2020-02-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多