You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在R中修改emmip生成的ggplot绘图的线型?

关于emmeans包emmip生成图调整线型失败的问题

我为研究交互效应,使用emmeans包(版本1.4.5;Lenth,2020)的emtrends()函数创建事后斜率,并通过emmip()可视化,代码如下:

emtrends(model_c, pairwise ~ Condition, var = "prsa_clean$meat_amount_c")
emmip(model_c, Condition ~ meat_amount_c, cov.reduce = range, ylab = "Favourability", xlab = "Meat consumption")

生成的图包含3个条件的斜率线,但不符合APA图表标准。我尝试用ggplot2调整,已经成功修改背景和线宽:

plot <- emmip(model_c, Condition ~ meat_amount_c, cov.reduce = range, ylab = "Favourability", xlab = "Meat consumption")
plot <- plot + theme_bw() + geom_line(size = 1.25)

但我希望给不同条件设置不同线型,尝试了以下代码均无效:

  • 代码1:
plot <- plot + theme_bw() +  geom_line(size = 1.25) + geom_line(linetype = "dashed")
  • 代码2:
plot <- plot + theme_bw() +  geom_line(size = 1.25) + geom_line(aes(linetype = Condition))
  • 代码3:
plot <- plot + theme_bw() +  geom_line(size = 1.25) + scale_linetype_manual(values=c("twodash", "dotted", "solid"))

我不常使用R,想了解为何geom_line(linetype)无法修改现有线型,而主题和线宽设置却能生效。

内容的提问来源于stack exchange,提问作者Vay

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 18:40:56