Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sjp.int linetype only in legend, not in graph #258

Closed
LisaRosenberger opened this issue Jul 26, 2017 · 8 comments
Closed

sjp.int linetype only in legend, not in graph #258

LisaRosenberger opened this issue Jul 26, 2017 · 8 comments

Comments

@LisaRosenberger
Copy link

I am trying to change the linetype of an interaction plot (with a factor and a continuous predictor) into a solid line and a dashed line by changing the linetype in sjp.setTheme():
sjp.setTheme(panel.bordercol = "white",axis.linecolor = "black",panel.gridcol="white",geom.linetype = c(1,3),base=theme_bw())
sjp.int(m10b,type="eff",int.term = "multiplication_factor:pleasantness",show.ci = TRUE)

interaction plot

However the linetype only changes in my legend, and not in the plot itself. Any idea why that is the case?

@strengejacke
Copy link
Owner

If you use geom.colors = "bw", the line type is applied to the plot, however, it uses black colors (see pkg vignette).

Do you want coloured geoms and different line types?

@LisaRosenberger
Copy link
Author

Ah, I didn´t see the vignette, sorry. So using the geom.colors = "bw" does the trick:
interaction plot2

However, what I was actually trying to make is a grey scale plot so that the CI´s are more distinguishable, like this:
interaction plot3
and there the linetypes didn´t change either. But now I know that it only works with black-and-white plots. And (like in colored plots) there is no actual need for different linetypes with greyscale plots.
Thanks for your quick reply!

@strengejacke
Copy link
Owner

There is a workaround, by using the returned plot object. sjp.int() returns a list of plots. You can then simply add another fill-scale:

library(ggplot2)
library(RColorBrewer)
library(sjPlot)

fit <- lm(weight ~ Diet * Time, data = ChickWeight)
p <- sjp.int(fit, type = "eff", geom.colors = "bw", show.ci = T)
# 4 colours for 4 CI-bands
p$plot.list[[1]] + scale_fill_manual(values = RColorBrewer::brewer.pal(4, "Greys"))

@LisaRosenberger
Copy link
Author

This works perfectly, thanks!

@cathytao
Copy link

How to solve the same problem, if using plot_model? I am using the following code and hope to have line dashed/solided across different levels. I did not find a proper solution!

plot_model(p8, type = "int", transform = "exp", terms = "x", geom.colors = "bw", pred.type = "fe", mdrt.values = "meansd")

@cathytao
Copy link

Sorry, wrong code -

plot_model(p8, type = "int", transform = "exp", terms = "x", colors = "bw", pred.type = "fe", mdrt.values = "meansd")

@strengejacke
Copy link
Owner

Either use ggeffects

library(ggeffects)
data(efc)
fit <- lm(neg_c_7 ~ c12hour * barthtot, data = efc)
ggpredict(fit, terms = c("c12hour", "barthtot")) %>% plot(colors = "bw")

or plot_model() with type = "pred" or type = "eff":

plot_model(fit, type = "pred", terms = c("c12hour", "barthtot"), colors = "bw")
plot_model(fit, type = "eff", terms = c("c12hour", "barthtot"), colors = "bw")

For type = "int", it looks like the color-argument is currently not passed down to plot().

strengejacke added a commit that referenced this issue Nov 16, 2018
@strengejacke
Copy link
Owner

Should work now with the latest commit to GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants