Sakuski
Sakuski

Reputation: 13

R: sjp.glmer changing x-axis lim, y-axis label from percentage to decimal, and confidence band colors

I've been using the sjPlot package in R for a while and I'm thoroughly enjoying it. Recently however, I've run into some problems that I can't figure myself.

(1) Using sjp.glmer(fe.prob), the x-axis labels/spacing seems to be derived from the to-be-plotted fixed factor. I can change the y-axis limit by using 'axis.lim', however, I struggle to change the x-axis limits.

(2) Since the last update (10.1.17 I think), the color-scheme has been changed slightly. As a result I can barely see my confidence bands. Theoretically I could change the background to make them more visible. However, what I'm looking for is to change the actual color of the confidence bands. I suspect this one can be changed using sjp.setTheme but I just can't figure out how.

(3) Also since the last update (I think), the y-axis for sjp.glmer of type "fe.prob" are labelled as percentages (1% to 100%) rather than decimals (0 to 1). Any hints how I can switch it back to decimals?

Here is an example line:

sjp.glmer(Model, 
          type = "fe.prob",
          vars = "Var1", 
          show.scatter = FALSE, 
          geom.colors = "Black", 
          width = 7.9, height = 6.8, 
          facet.grid = FALSE, 
          show.ci = TRUE, 
          axis.lim = c(0,1)) 

Below are also my Sjp.SetTheme settings.

I hope this illustrates the issues: Example Figure

Any help is appreciated.

Best, S

sjp.setTheme(base = theme_grey(),
             geom.outline.color = "black",
             theme.font = 'Times',
             geom.outline.size = 1, 
             geom.label.size = 2,
             geom.label.color = "black",
             title.color = "black", 
             title.size = 1.0, 
             axis.title.size = 1.0,
             axis.title.color =  "black",
             axis.angle.x = 0,
             axis.textsize.x = 1.0,
             axis.textsize.y = 1.0,
             axis.textcolor = "black")

Upvotes: 1

Views: 2514

Answers (1)

Daniel
Daniel

Reputation: 7832

Your requested issues can't directly be modifed via sjp.glmer - however, you can use the returned ggplot-object for further manipulation.

library(sjPlot)
library(lme4)
library(ggplot2)
library(sjmisc)

# create binary response
sleepstudy$Reaction.dicho <- dicho(sleepstudy$Reaction, dich.by = "median")
# fit model
fit <- glmer(Reaction.dicho ~ Days + (Days | Subject),
             data = sleepstudy, family = binomial("logit"))

p <- sjp.glmer(fit, type = "fe.prob", vars = "Days", 
               show.scatter = FALSE, geom.colors = "Black", 
               facet.grid = FALSE, show.ci = TRUE)

# get first plot of all created plots (in this case, just one plot)
# and change x-axis-limits and use another metric on y-scale
p$plot.list[[1]] + xlim(0, 4) + scale_y_continuous(limits = c(0, 1))

enter image description here

Still, the confidence bands are of very high transparancy, but I'm quite not sure how to change the alpha-level for stat_smooth. I'll look for a solution...

Upvotes: 4

Related Questions