0

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
  • Welcome to SO! It would be easier to help you if you provide a minimal reproducible example including a snippet of your data best shared using dput() or using some fake data or using a built-in dataset. Commented Mar 15, 2024 at 13:21

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank's so much !!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.