R 与因子交互时的批间标签

R 与因子交互时的批间标签,r,plot,lm,interaction,R,Plot,Lm,Interaction,因此,我需要使用R中的interplot绘制因子变量的相互作用。我已经能够解决所有问题,除了其中的一个重要部分:如何更改绘制的因子的标签。下面是一个可复制的示例,显示了该问题: set.seed(507) df <- data.frame( outcome = sample(1:7, 1000, replace = T), scale = sample(1:7, 1000, replace = T), dummy = sample(0:2, 1000, replace = T)

因此,我需要使用R中的
interplot
绘制因子变量的相互作用。我已经能够解决所有问题,除了其中的一个重要部分:如何更改绘制的因子的标签。下面是一个可复制的示例,显示了该问题:

set.seed(507)
df <- data.frame(
  outcome = sample(1:7, 1000, replace = T),
  scale = sample(1:7, 1000, replace = T),
  dummy = sample(0:2, 1000, replace = T))

# factor the dummy
df$dummyf <- factor(df$dummy)

# linear model
lm.out <- lm(outcome ~ scale * dummyf, data = df)

# interplot
library(interplot)
interplot(lm.out, "dummyf", "scale", plot = T, hist = F, ci = 0.95)

我还试图修改
ggplot2
的各个方面,因为
interplot
使用
ggplot2
,但也无法使其正常工作。有什么建议吗?提前谢谢

您将不得不修改。它只是将整数附加到变量名,而不是级别

解决方案如下所示:

library(interplot)
set.seed(507)
df <- data.frame(
  outcome = sample(1:7, 1000, replace = T),
  scale = sample(1:7, 1000, replace = T),
  dummy = sample(0:2, 1000, replace = T))

# factor the dummy
df$LABEL <- factor(df$dummy)
# df$LABEL <- df$dummyf
lm.out.1 <- lm(outcome ~ scale * LABEL, data = df)
interplot(lm.out.1, "LABEL", "scale", plot = T, hist = F, ci = 0.95)
库(批间)
种子集(507)
df
library(interplot)
set.seed(507)
df <- data.frame(
  outcome = sample(1:7, 1000, replace = T),
  scale = sample(1:7, 1000, replace = T),
  dummy = sample(0:2, 1000, replace = T))

# factor the dummy
df$LABEL <- factor(df$dummy)
# df$LABEL <- df$dummyf
lm.out.1 <- lm(outcome ~ scale * LABEL, data = df)
interplot(lm.out.1, "LABEL", "scale", plot = T, hist = F, ci = 0.95)