0
所以我需要在R中使用interplot
来描绘一个因子变量的相互作用。除了其中一个重要部分外,我已经能够将所有东西都映射出来:如何更改获取因子的标签绘制。这里的显示问题可复制例如: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)
一旦我绘制这里的相互作用是我得到:
现在,我需要能够改变dummyf1
和dummyf2
标签的面读基本上是LABEL1
和LABEL2
。这里有一个可能的解决办法我试过但没有得到我我需要什么:
# possible solution?
levels(df$dummyf)[levels(df$dummyf) == 1] <- "LABEL1"
levels(df$dummyf)[levels(df$dummyf) == 2] <- "LABEL2"
# linear model
lm.out.1 <- lm(outcome ~ scale * dummyf, data = df)
# interplot
library(interplot)
interplot(lm.out, "dummyf", "scale", plot = T, hist = F, ci = 0.95)
我还试图修改的ggplot2
的方面,因为interplot
使用ggplot2
,但一直没能得到它的工作的。有什么建议么?提前致谢!