Change lines types in interact_plot function

30 views Asked by At

I use interact_plot to visualise the interaction effect of my numerical moderator (mean; +1SD; -1SD).

The problem is that the lines for mean and +1SD are dashed and for -1SD solid.

I would like to visualise my mean as a solid line and the two SD as a dashed line, but I can't find the code.

Here is my current code:

mod1plot <- interact_plot(mod1, pred=TIME, modx=N, plot.points = TRUE,
                          int.width = 0.5, y.label = 'Score au Moca', x.label = 'Avant/après rééducation', main.title = 'Effet modérateur du névrosisme sur le Moca', legend.main = 'Névrosisme', colors = 'Blues',
                          line_styles = line_styles, vary.lty = TRUE)

mod1plot 

And I would like to display my mean as a solid line and the two SD as a dashed line, but I can't figure out how to do this.

1

There are 1 answers

1
stefan On

As interactions::interact_plot returns a ggplot object you can manipulate it as such, i.e. you can change the linetypes using scale_linetype_manual.

Using a minimal reproducible example based on the default example from ?interactions::interact_plot:

library(interactions)
library(ggplot2)

states <- as.data.frame(state.x77)
states$HSGrad <- states$`HS Grad`
mod1 <- lm(Income ~ HSGrad + Murder * Illiteracy, data = states)

interact_plot(mod1,
  pred = Murder, modx = Illiteracy,
  plot.points = TRUE, int.width = 0.5,
  y.label = "Score au Moca",
  x.label = "Avant/après rééducation",
  main.title = "Effet modérateur du névrosisme sur le Moca",
  legend.main = "Névrosisme", colors = "Blues",
  vary.lty = TRUE
) +
  scale_linetype_manual(
    name = "Névrosisme",
    values = c("dashed", "solid", "dashed")
  )
#> Scale for linetype is already present.
#> Adding another scale for linetype, which will replace the existing scale.