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

如何优化R语言绘制的交互效应图,提升交互效果辨识度?

学术论文交互效应图优化建议

我正在撰写学术论文,需要纳入交互效应图。目前用R语言的plot_model函数绘制了图,但不确定如何优化来增强交互效应的可见性,现有R代码和生成的图表如下:

当前代码

plot_model4 <-
  plot_model(
    model4,
    type = "int",
    terms = c("log_EU_immigration_cumulative_4yr", "lknemny"),
    ci.lvl = 0.95
    ) +
  labs(
    title = paste0("Predicted Welfare State Support Based on Exposure to EU ",
                   "Immigration and Individual Financial Insecurity"
                   ),
    x = "Cumulative EU Immigration (Log, Last 4 Years)",
    y = "Predicted Support for Welfare State",
    color = paste0("Financial Insecurity Likelihood: How likely not enough ",
                   "money for household necessities next 12 months"
                   )
    ) +
  scale_color_manual(
    values = c("#984464", "#BFA5A3", "#449777", "#A4D8A0"),
    labels = c("Not at all likely", "Not very likely", "Likely", "Very likely")
    ) +
  theme_minimal() +
  theme(legend.position = "right") +
  scale_x_continuous(breaks = scales::pretty_breaks(n = 10)) +
  scale_y_continuous(breaks = scales::pretty_breaks(n = 10))

当前图表

交互效应图


优化方案(增强交互效应可见性)

1. 强化分组区分度

  • 调整配色:现有部分颜色对比度偏低,可改用专业配色库提升区分度,比如RColorBrewer的Paired色卡:
    library(RColorBrewer)
    scale_color_manual(values = brewer.pal(4, "Paired"),
                       labels = c("完全不可能", "不太可能", "可能", "非常可能"))
    
  • 添加线型差异:给不同分组线条搭配不同线型(实线、虚线、点线等),确保黑白打印也能清晰区分:
    scale_linetype_manual(values = c("solid", "dashed", "dotted", "dotdash"),
                          labels = c("完全不可能", "不太可能", "可能", "非常可能"))
    
    需在plot_model中同步映射线型,或通过aes(linetype = lknemny)手动绑定分组变量。

2. 聚焦交互核心区域

  • 标注线条交点:若交互效应显著,计算并标注不同分组线条的交点,用geom_point突出显示,同时标注坐标值强化关键信息。
  • 高亮差异区间:用geom_rect在x轴上圈出斜率差异最明显的区间,引导读者关注交互效应的核心表现区域。

3. 简化文本与刻度

  • 精简坐标轴刻度:当前x/y轴10个刻度过于密集,调整为5-6个更清晰:
    scale_x_continuous(breaks = scales::pretty_breaks(n = 5))
    scale_y_continuous(breaks = scales::pretty_breaks(n = 5))
    
  • 缩短图例标题:将过长的图例标题简化为“财务不安全感可能性”,避免换行影响可读性:
    labs(color = "财务不安全感可能性")
    

4. 补充显著性信息

若模型中交互项显著,可在图中添加显著性标注:比如在斜率差异最大的位置用geom_text标注*/**,或在标题下方补充交互效应的显著性水平说明。

5. 优化布局细节

  • 调整图例位置:将图例移至图表下方并横向排列,避免挤占绘图区域:
    theme(legend.position = "bottom", legend.direction = "horizontal")
    
  • 加粗线条宽度:通过add.args = list(size = 1.2)传入plot_model,让线条更醒目。

优化后示例代码

library(RColorBrewer)

plot_model4 <-
  plot_model(
    model4,
    type = "int",
    terms = c("log_EU_immigration_cumulative_4yr", "lknemny"),
    ci.lvl = 0.95,
    add.args = list(size = 1.2)  # 增加线条宽度
    ) +
  labs(
    title = "基于欧盟移民接触程度与个人财务不安全感的福利国家支持预测",
    x = "累计欧盟移民(对数,过去4年)",
    y = "福利国家支持预测值",
    color = "财务不安全感可能性",
    linetype = "财务不安全感可能性"
    ) +
  scale_color_manual(
    values = brewer.pal(4, "Paired"),
    labels = c("完全不可能", "不太可能", "可能", "非常可能")
    ) +
  scale_linetype_manual(
    values = c("solid", "dashed", "dotted", "dotdash"),
    labels = c("完全不可能", "不太可能", "可能", "非常可能")
    ) +
  theme_minimal(base_size = 12) +
  theme(
    legend.position = "bottom",
    legend.direction = "horizontal",
    plot.title = element_text(hjust = 0.5)  # 标题居中
    ) +
  scale_x_continuous(breaks = scales::pretty_breaks(n = 5)) +
  scale_y_continuous(breaks = scales::pretty_breaks(n = 5))

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 22:09:55