John Ryan
John Ryan

Reputation: 373

Renaming Factor on Axis in sjPlot for Forest Plot in R

I have a logistic regression that I'm trying to plot on a forest plot using plot_model from sjPlot.

I'm able to rename the continuous variable names on the Y-axis to look nice - but how do I rename when there's a factor? i.e. I don't want it to say "as.factor(vs)1" in the example below - I want it to say "Engine Type - 1".

library(sjPlot)

m1<-glm(am ~ qsec + as.factor(vs), family="binomial", data=mtcars)

p1<-plot_model(m1,  
              show.values = TRUE, 
              value.offset = .3,
              auto.label = FALSE) + 
  scale_x_discrete(labels=list(
    qsec = "1/4 Mile Time",
    vs = "Engine Type - 1"
  ))

Plot

Upvotes: 1

Views: 395

Answers (1)

John Ryan
John Ryan

Reputation: 373

I got it - You have to just feed it the label that it was already adding to the plot.

p1<-plot_model(m1,  
              show.values = TRUE, 
              value.offset = .3,
              auto.label = FALSE) + 
  scale_x_discrete(labels=list(
    qsec = "1/4 Mile Time",
    as.factor(vs)1 = "Engine Type - 1"
  ))

Upvotes: 1

Related Questions