Cole Robertson
Cole Robertson

Reputation: 649

axis.title = is not working in sjp.lmer() in the sjPlot package

I'm doing some plotting of some mixed models I've been running and am pulling my hair out trying to make sjp.lmer() change the x and y axis labels of a fixed effect. If I'm missing something simple, please let me know!

This is my code:

library(sjPlot);library(lme4)

model = lmer(DV ~ IV + (1|groupingVariable), data = data, REML = F)

sjp.lmer(model, 
     type = "fe.slope", 
     vars = c("IV"),
     title = "Estimated effect of IV1 on DV", 
     geom.colors = c("black", "grey49"), 
     show.ci = T, 
     axis.title = c("IV Title", "DV Title"))

Model is a formal model estimated using glmer(). The problem is that regardless of what I write, the x and y labels do not change.

I think the syntax is correct, because this code works:

sjp.lmer(model, 
     type = "re", 
     sort.est = "sort.all", 
     facet.grid = F,
     axis.title = c("IV Title", "DV Title"))

This second being a plot of the random effects for the same model. Is this a bug? Can you for some reason not specify axis labels for fixed effect models? Thank you!

Seems like a bug. I've raised the issue on gitHub at:

https://github.com/sjPlot/devel/issues/212

Upvotes: 1

Views: 889

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226627

As far as I can tell it's just an oversight ("misfeature"/bug). Looking at the code here:

reglinplot <- reglinplot +
  labs(title = title,
       x = sjmisc::get_label(model_data[[p_v]], def.value = p_v),
       y = response)

it seems the labels are hard-coded. Furthermore, the argument list of sjp.reglin (here) doesn't have an axis.title argument ... posting an issue, as you have done, seems like the right way forward.

However, it's not too hard to hack the plot a little bit if you know just a tiny bit about the ggplot2 package.

Set up example:

library(sjPlot); library(lme4
mod <- lmer(Reaction~Days+(Days|Subject),sleepstudy)
p1 <- sjp.lmer(mod, 
     type = "fe.slope", 
     vars = "Days")  ## stripped-down (warning about colour palette)

Hack labels:

library(ggplot2)
p1$plot.list[[1]] + labs(x="hello",y="goodbye")

Upvotes: 2

Related Questions