【问题标题】:How to remove gridlines from interact_plot如何从interact_plot中删除网格线
【发布时间】:2021-11-05 02:48:38
【问题描述】:

我正在尝试从 R Studio 中的 interact_plot 中删除网格线,据我所知,它使用 ggplot2 绘图。

我已经尝试了 ggplot2 中的以下代码:

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"), 
  theme(panel.grid = element_blank())
)

但我收到此错误消息:

Mean_Mor_Con2 和 Agreement2 和 theme(panel.grid = element_blank()) 不是 包含在模型中与彼此的交互中。名称错误(modxvals2)

我在尝试使用主题(例如theme_bw())时也会收到相同的错误消息。

非常感谢任何帮助!

This is the graph I'm getting

【问题讨论】:

标签: r ggplot2 interaction gridlines


【解决方案1】:

函数interact_plot返回一个ggplot类型的对象,然后可以修改它,而不是直接在这个函数内部:

plt <- 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")
)

plt <- plt + theme(panel.grid.major = element_blank())

plt

【讨论】:

  • 非常感谢您的回复@danloo。我尝试了您的代码,但它没有给我错误代码,但不幸的是它给了我与以前相同的图(带有浅灰色网格线)。有什么想法吗?
  • 请张贴制作的图片。每个人都拥有数据的可重复示例也将对我们有所帮助。
  • 我已将生成的图像添加到原始帖子中。我无法将我的数据集从 R(创建了所有度量)导出回 excel 或 CSV,但如果我的图像没有帮助,我会再试一次。
  • 我更新了答案。这是panel.grid.major。我建议使用writexl 将数据框导出到excel。 CSV 不保留格式,因此可能存在一些导入问题。
  • 是的,成功了!非常感谢您的帮助@danlooo !!
猜你喜欢
  • 1970-01-01
  • 2014-02-21
  • 2016-07-14
  • 2017-12-04
  • 1970-01-01
  • 2018-09-27
  • 2019-01-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多