user7592911
user7592911

Reputation:

Defining y-axis range and breaks in package sjPlot:: plot_model()

I am plotting the results of my GlmmTMB model with the sjplot package and the function plot_model (max.m3) in R. Here is the Code:

p=sjPlot::plot_model(max.m3, type="pred", grid = F)

These are six graphics which are plotted than. However, I would like to define y-axis range (ranging from 0 to 10) and shown breaks (0,5,10 = so that tick marks appear at 0, 5, and 10).

Unfortunately, I did not find a solution to do this.

Upvotes: 2

Views: 2397

Answers (1)

Daniel
Daniel

Reputation: 7832

If you plot marginal effects for all model terms, plot_model() returns a list of ggplot-objects. You can then modify each plot in the list, simply using ggplot-commands.

m <- lm(mpg ~ hp + gear + cyl + drat, data = mtcars)
p <- sjPlot::plot_model(m, type = "pred", grid = FALSE)
p[[1]] + scale_y_continuous(limits = c(15, 30), breaks = c(15, 25, 30))
p[[2]] + scale_y_continuous(limits = c(5, 40), breaks = c(15, 25, 40))
...

If you want to apply the same y-limits and breaks to all plots, you can loop over the list, e.g.:

library(ggplot2)
m <- lm(mpg ~ hp + gear + cyl + drat, data = mtcars)
p <- sjPlot::plot_model(m, type = "pred", grid = FALSE)
lapply(p, function(i) i + scale_y_continuous(limits = c(15, 30), breaks = c(15, 25, 30)))

Upvotes: 2

Related Questions