增加 `emmeans` 比较箭头的粗细

Increase `emmeans` comparison arrows' thickness

我正在寻找增加箭头粗细的巧妙方法。我的粗略想法是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)

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

首先,你是一个传奇,因为你映射到 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-05-30 创建