簡體   English   中英

R 中的 Plot:x 軸的開始和結束間隙 - 如何消除?

[英]Plot in R: Gap beginning and end of the x-axis - how to remove?

那是我的代碼

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 結束?

sjPlot 使用 ggplot2,因此您可以通過查找 ggplot2 找到修改 plot 的選項。 在這種情況下,您需要的是 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))

在此處輸入圖像描述

也許通過在 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))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM