Catherine
Catherine

Reputation: 161

Change scale in plot_model function

I am trying to use the plot_model() function (sjPlot package) in R. However, it only allow me to use the minimum range of x-axis as -1 to 1. Since my estimates are very small, I would like to change the range to -0.2 to 0.2. I have tried this code:

sjPlot::plot_model(lm_PMd2, 
                  axis.labels=c("TimeInterval", 
                                "FactorAnalyses_diff"),
                  show.values=TRUE, show.p=TRUE,
                  colors = "#ec7014", 
                  title="PMd", axis.lim = c(-0.2, 0.2)) +
 theme_bw()+ 
 theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
       text = element_text(size = 12))

Any insight is helpful. Thanks!

Upvotes: 0

Views: 1002

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226637

I think you can do this (no reproducible example given, so I made one up):

m1 <- lm(Murder ~ UrbanPop, data = USArrests)
library(sjPlot)
plot_model(m1) + scale_y_continuous(limits = c(-0.2, 0.2))
  • you will get a message ("Scale for 'y' is already present ..."), which you can ignore
  • it may be confusing that the code above tells ggplot to override the y-axis (rather than the x-axis, which is what it looks like on the plot): this is (I assume) because the package internally uses a coord_flip() specification.
  • it's not obvious to me why axis.lim = c(-0.2, 0.2) doesn't do what you want — perhaps it's either a bug or confusingly documented?

Numeric vector of length 2, defining the range of the plot axis. Depending on plot-type, may effect [sic] either x- or y-axis. For Marginal Effects plots, ‘axis.lim’ may also be a list of two vectors of length 2, defining axis limits for both the x and y axis.

Upvotes: 0

Related Questions