如何在交互图中显示标准化的y得分

时间:2019-06-26 15:25:22

标签: r ggplot2

我正在尝试使用“ interplot”软件包在R中绘制标准化数据的双向交互。但是,显示的y得分不再标准化。为什么会这样,我该如何解决?

我试图更改y限制并使用“ scale_y_continuous()”函数。

# generate data
x <- rnorm(100, 0, 1)
y <- x + rnorm(100, 0, 1)
z <- y + rnorm(100, 0, 1)
df <- as.data.frame(cbind(x,y,z)) 

# build model with interaction term
model1 <- glm(y ~ x*z, data=df)

# plot interaction
require(interplot)
interplot(model1, var1 = "x",var2 = "z", ci = 0.95, predPro = TRUE,
    var2_vals = c(-1, 1), hist=F) + xlim(-3, 3) +
    theme_classic()

由于分数是标准化的,所以我希望y刻度显示介于-3和+3之间的值。但是,显示的y值在20到80之间。

1 个答案:

答案 0 :(得分:0)

借助?interplot示例:

set.seed(123)
# generate data
x <- rnorm(100, 0, 1)
y <- x + rnorm(100, 0, 1)
z <- y + rnorm(100, 0, 1)
df <- as.data.frame(cbind(x,y,z))

# build model with interaction term
model1 <- glm(y ~ x*z, data=df)
# lm(y ~ x*z, data=df) # glm => is a linear model

# plot interaction
require(interplot, quietly = TRUE, warn.conflicts = FALSE)
interplot(model1, var1 = "x",var2 = "z", ci = 0.95,
          predPro = TRUE, var2_vals = c(-1,1)) +
        xlim(-3, 3) +
        xlab("x values") +
        ylab("Estimated Coefficient for z") +
        ggtitle('Estimated Coefficient of z by x conditionnally to y in c(-1,1)') +
        theme_classic()


interplot(model1, var1 = "x",var2 = "z", ci = 0.95) +
        xlim(-3, 3) +
        xlab("x values") +
        ylab("Estimated Coefficient for z") +
        ggtitle('Estimated Coefficient of z by x') +
        theme_classic()
#> Warning: Removed 28 rows containing missing values (geom_path).