我正在寻找一种巧妙的方法来增加箭头的厚度。我的粗略想法是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)
如何更改我的代码?非常感谢。
答案 0 :(得分:1)
首先,您是一个图例,因为您映射到 size
aes 而不是使用大小作为参数,即在 aes()
之外。其次,由于 arrow()
没有 size 参数,您会收到错误消息。请参阅?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 日创建