更改interact_plot函数中的线条类型

问题描述 投票:0回答:1

我使用

interact_plot
来可视化我的数值调节器的交互效果(平均值;+1SD;-1SD)。

问题在于平均值和+1SD 的线是虚线,-1SD 的线是实线。

我想将我的平均值可视化为实线,将两个 SD 可视化为虚线,但我找不到代码。

这是我当前的代码

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 

我想将我的平均值显示为实线,将两个SD显示为虚线,但我不知道如何做到这一点。

r plot interaction
1个回答
0
投票

由于

interactions::interact_plot
返回一个
ggplot
对象,您可以对其进行操作,即您可以使用
scale_linetype_manual
更改线型。

使用基于

?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.

© www.soinside.com 2019 - 2024. All rights reserved.