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

如何移除R中interact_plot函数生成图表的网格线

报错原因

你将theme()、theme_bw()等ggplot2主题函数直接传入了interact_plot的参数列表,函数会将其识别为模型变量参数,自然会抛出「未包含在交互项中」的错误。

解决方案

interact_plot生成的结果本身就是标准的ggplot2对象,你可以用以下两种方法调整主题:

方法1:先存图再叠加主题层(更灵活,推荐)

# 先将交互图赋值为ggplot对象
p <- interact_plot(
  MC_Feat_Sit, 
  pred =  Mean_Mor_Con2, 
  modx = Agreement2, 
  modx.values = c(1, 4, 7), 
  x.label = "Moral Conviction", 
  y.label = "Situational Attributions", 
  legend.main = "Agreement", 
  modx.labels = c("Strongly Disagree", "Neutral", "Strongly Agree")
)

# 叠加主题设置移除网格线,也可叠加其他ggplot2图层
p + theme(panel.grid = element_blank())

# 若要使用预设主题,按如下写法即可
# p + theme_bw() + theme(panel.grid = element_blank())

方法2:通过interact_plot自带的ggplot2.theme参数传入

interact_plot(
  MC_Feat_Sit, 
  pred =  Mean_Mor_Con2, 
  modx = Agreement2, 
  modx.values = c(1, 4, 7), 
  x.label = "Moral Conviction", 
  y.label = "Situational Attributions", 
  legend.main = "Agreement", 
  modx.labels = c("Strongly Disagree", "Neutral", "Strongly Agree"),
  ggplot2.theme = theme_bw() + theme(panel.grid = element_blank())
)

内容的提问来源于stack exchange,提问作者E.J. Woodrow

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.04 23:21:03