1

That is my code

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

And this is what I get

How can I remove the two gaps such that the x axis starts at 3 and ends at 7?

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
Mariella
  • 21
  • 4

2 Answers2

2

sjPlot uses ggplot2 so you can find the options to modifying your plot by looking for ggplot2. In this case, what you need is expand=c(0,0) inside scale_x_continuous, for example:

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

enter image description here

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
1

Maybe change your scale with the following addition to your 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))
Dom
  • 1,043
  • 2
  • 10
  • 20