I'm trying to edit the names of the factor levels of a predictor variable in R for an effect plot with the jtools package. I should be able to do this with the "pred.labels" argument, but the labels don't change. For example, using the mtcars data set I try to write out the predictor names ("four", "six", "eight") but there is no change in the figure.
data(mtcars)
mtcars$cyl <- factor(mtcars$cyl)
mtest <- lm(mpg ~ cyl + hp + wt, data = mtcars)
effect_plot(mtest, pred = cyl, pred.labels = c("four", "six", "eight"))

Now, if this were really my problem I would just overwrite the factor levels in the data. However, in my data set I have many factors that should have a space in their name for easy interpretation, so I don't want to recode my variables this way. Any idea how to fix this?
Thanks
Since jtools seems to use ggplot2 you can just change the labels like you would if you were using ggplot2
label <- c("four", "six", "eight")
effect_plot(mtest, pred = cyl) + scale_x_discrete(labels= label)
or
effect_plot(mtest, pred = cyl) + scale_x_discrete(labels= c("four", "six", "eight"))

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With