g.race
g.race

Reputation: 15

sjPlot interaction plot_model. How to plot between major grid lines, edit graph for visual appeal

I am trying to plot predicted values for model containing an interaction. I would like to move the position of the x-axis values (factors) closer to the centre of the graph. Currently using sjPlot, plot_model() function and I have tried using grid.breaks= but this only works for numeric values. Furthermore, everything I try, the values seem to only plot along the major grid lines. Is there not a way to plot between major grid lines? Alternatively is there a way to do this in ggplot2? TIA

library("sjPlot")
data("mtcars")
mtcars$gear <- factor(mtcars$gear)
mtcars <- subset(mtcars,!gear=="3")
mtcars$gear <- factor(mtcars$gear)
levels(mtcars$gear)
m_gear <- lm(mpg ~ gear*wt, data = mtcars)
plot_model(m_gear, type = "int", grid.breaks = 0.5)

graph output

Upvotes: 1

Views: 651

Answers (1)

StupidWolf
StupidWolf

Reputation: 46908

You can use coord_cartesian. When you have factors, they are encoded as 1,2 on the x-axis, so setting the limits beyond that will give you what you need, see:

plot_model(m_gear, type = "int") + coord_cartesian(expand = TRUE,xlim=c(0,3))

enter image description here

plot_model(m_gear, type = "int") + coord_cartesian(expand = TRUE,xlim=c(0.5,2.5))

enter image description here

Upvotes: 0

Related Questions