【问题标题】:Plot in R: Gap beginning and end of the x-axis - how to remove?R中的绘图:x轴的开始和结束间隙 - 如何删除?
【发布时间】:2020-06-26 11:48:57
【问题描述】:

这是我的代码

plot_model(mylogit, type = "pred", terms = c("ScoreEnvAtt [all]", "Guilt")) + 
  scale_colour_discrete(guide = guide_legend(title = "Guilt"), labels = c("Low", "Medium", "High")) + 
  scale_fill_discrete(guide = guide_legend(title = "Guilt"), labels = c("Low", "Medium", "High"))  +
  labs( title = "",
        x = "Environmental Attitudes",
        y = "Probability of choosing the green investment") + theme_gray(base_size = 14)  + 
  theme(text=element_text(family="Times New Roman", size=12)) 

如何消除两个间隙,使 x 轴从 3 开始到 7 结束?

【问题讨论】:

  • 如果这里的某些专业人士在情节中看到一些视觉上令人讨厌的东西并告诉我如何使它变得更好,我也非常感谢 - 我正在将它用于我的论文。
  • 这能回答你的问题吗? Force the origin to start at 0
  • @AdamQuek 啊,是的,这就是下面其他人提出的解决方案,谢谢!!
  • @BappaDas 我以前看过这个帖子,但是没有用。

标签: r ggplot2 plot sjplot


【解决方案1】:

sjPlot 使用 ggplot2,因此您可以通过查找 ggplot2 来找到修改绘图的选项。在这种情况下,您需要在 scale_x_continuous 中进行 expand=c(0,0),例如:

library(sjPlot)
fit = lm(mpg ~ hp,data=mtcars)
plot_model(fit,typpe="pred") + scale_x_continuous(expand=c(0,0))

【讨论】:

    【解决方案2】:

    也许在你的 ggplot 中添加以下内容来改变你的比例:

     plot_model(mylogit, type = "pred", terms = c("ScoreEnvAtt [all]", "Guilt")) + 
     scale_colour_discrete(guide = guide_legend(title = "Guilt"), labels = c("Low", "Medium", "High")) + 
     scale_fill_discrete(guide = guide_legend(title = "Guilt"), labels = c("Low", "Medium", "High"))  +
     labs( title = "",
        x = "Environmental Attitudes",
        y = "Probability of choosing the green investment") + theme_gray(base_size = 14) + 
      theme(text=element_text(family="Times New Roman", size=12)) + 
      scale_x_continuous(limits = c(3, 7), expand = c(0, 0))
    

    【讨论】:

      猜你喜欢
      • 2018-05-23
      • 2018-02-23
      • 1970-01-01
      • 2020-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-03
      • 1970-01-01
      相关资源
      最近更新 更多