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!!

MKS.bln
  • 33
  • 5

1 Answers1

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

Daniel
  • 7,252
  • 6
  • 26
  • 38
  • Thank you for the super quick answer. – MKS.bln Oct 04 '18 at 15:22
  • It did set my lines to greyscale or b/w, respectively. However, in b/w it did not automatically differentiate the linetype (I have two different lines, originally blue & red), e.g., with one solid, one dashed line, as you point out in the vignettes. I tried adding a `linetype = c(1,2)`-argument to `plot_model()` but that didn't do the trick. Is there a way to manually adjust the linetype? – MKS.bln Oct 04 '18 at 15:28
  • I added a working example. I'm not sure what exactly does not work for you, maybe you can [file an issue](https://github.com/strengejacke/sjPlot/issues)? If you want to change the line-types – Daniel Oct 05 '18 at 08:08
  • colors="bw" parameter is all I need to convert the theme color to black and white. – Aryo Oct 16 '19 at 04:02
  • colors="bw" is working for me, but it overwrites my nice legend.title(). Any suggestions? – Dustin Jul 20 '23 at 20:50
  • Used sjlabelled::set_label() and it worked! – Dustin Jul 20 '23 at 23:01