3

I am plotting a regression model with sjPlot's plot_model(). I want to change my line colors from sjPlot theme (red & blue lines) to black & white or grayscale. However, when I utilize set_theme(theme_bw()), the plot appearance does not change (theme_bw is from ggplot2, according to the dropdown I see while typing the function).

The plot appearance however does change when I select one of the available sjPlot themes (theme_538, theme_blank, theme_sjplot and theme_sjplot2), which all render the lines red & blue, but change the plot background, so I think I got the function right.

How can I use a bw or gs theme or manually set the line colors to black & white for my plot?

library(ggplot2)
library(sjPlot)
library(sjmisc)
#set_theme(theme_bw()) # this does not change the plot appearance 
set_theme(theme_538()) # this does change the plot background appearance 

M <- glm(DV ~ IV1 + IV2 + IV3 + IV1*IV2*IV3, data = data5, family = quasibinomial("logit"))
p <- plot_model(M, type = "pred", terms = c("IV1", "IV2", "IV3 [-1,0,1]"), theme = theme_get())
p

ps: according to the sjPlot resources I find online, there should be more sjPlot themes available than those I see. That is strange. Moreover, I read that the set_theme() function should work with ggplot2 themes, which seems to not be the case here. Any ideas where the bug is? Maybe I am overseeing something very simple?

edit: I am using R version 3.5.0 and Rstudio version 1.1.383 Thank you!!

4

1 回答 1

1

The theme-options changes the appearance of grids and axis labels etc., but not of the geoms (like dots or lines). Therefore you can use the colors-argument in plot_model(). There are some examples in this vignettes. I guess the solution for you would be:

plot_model(M, type = "pred", terms = c("IV1", "IV2", "IV3 [-1,0,1]"), colors = "gs")

or

plot_model(M, type = "pred", terms = c("IV1", "IV2", "IV3 [-1,0,1]"), colors = "bw")


library(sjPlot)
data(efc)
fit <- lm(barthtot ~ c12hour + neg_c_7 * c161sex * c172code, data = efc)
plot_model(fit, type = "pred", terms = c("neg_c_7", "c172code", "c161sex"), colors = "bw")

enter image description here

plot_model(fit, type = "pred", terms = c("neg_c_7", "c172code", "c161sex"), colors = "gs")

enter image description here

于 2018-10-04T13:01:02.600 回答