简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM