【发布时间】:2022-07-22 01:20:39
【问题描述】:
我想用 R 中的一个结果绘制两个变量之间的交互效应。虽然我可以使用 sjPlot:plot_model() 成功生成图形,但当我调整 x 轴值时交互图不会调整大小。相反,绘制的图形始终是原始大小的图形,而 x 轴和 y 轴将调整。下面是在 R 中使用 mtcars 数据的示例。
library(sjPlot)
library(sjmisc)
library(ggplot2)
mtcars.df <- mtcars
fit <- lm(mpg ~ hp * disp, data = mtcars.df)
plot_model(fit, type = "pred", terms = c("hp", "disp"))
我可以在自己的代码中得到这样的图表。但是,当我尝试如下所示更改 x 轴和 y 轴时,网格会扩展,但图形本身不会。
plot_model(fit, type = "pred", terms = c("hp", "disp"), axis.lim = list(c(0,150),c(0,200)))
通过对坐标轴的极度夸张调整成功绘制交互图。图形不会延伸,但网格会延伸。
我可以使用什么代码来调整交互效果的线条和网格的线条?调整事后
plot_model(fit, type = "pred", terms = c("hp", "disp"))+xlim(0,150)
产生同样的问题。
事后扩展图表会产生同样的问题。
【问题讨论】: