sjplot:如何指定因变量?

发布于 2025-01-20 23:39:11 字数 803 浏览 4 评论 0原文

我有一个关于 sjPlot、plot_models 函数的简短问题。

我有这个代码:

fit1 <- lm(mpg ~ wt + cyl + disp + gear, data = mtcars)
fit2 <- update(fit1, . ~ . + hp)
fit3 <- update(fit2, . ~ . + am)


fit4 <- lm(hp ~ wt + cyl + disp + gear, data = mtcars)
fit5 <- update(fit4, . ~ . + hp)
fit6 <- update(fit5, . ~ . + am)


fit7 <- lm(cyl ~ wt + cyl + disp + gear, data = mtcars)
fit8 <- update(fit7, . ~ . + hp)
fit9 <- update(fit8, . ~ . + am)



plot_models(fit1, fit2, fit3, fit4, fit5, fit6, fit7, fit8, fit9,std.est = "std2")

生成这个:

在此处输入图像描述

如何将引用 MPG 的所有因变量编码为蓝色,引用 hp 的所有因变量编码为绿色,以及引用 cyl 的所有因变量为估计中的黄色 阴谋?那么标签应该相应更新吗?

I have a short question about the sjPlot, plot_models function.

I have this code:

fit1 <- lm(mpg ~ wt + cyl + disp + gear, data = mtcars)
fit2 <- update(fit1, . ~ . + hp)
fit3 <- update(fit2, . ~ . + am)


fit4 <- lm(hp ~ wt + cyl + disp + gear, data = mtcars)
fit5 <- update(fit4, . ~ . + hp)
fit6 <- update(fit5, . ~ . + am)


fit7 <- lm(cyl ~ wt + cyl + disp + gear, data = mtcars)
fit8 <- update(fit7, . ~ . + hp)
fit9 <- update(fit8, . ~ . + am)



plot_models(fit1, fit2, fit3, fit4, fit5, fit6, fit7, fit8, fit9,std.est = "std2")

Which generates this:

enter image description here

How can I code all dependent variables that refer to MPG as blue, all dependent variables that refer to hp as green, and all dependent variables that refer to cyl as yellow in the estimates plot? And then the label should update correspondingly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

音栖息无 2025-01-27 23:39:11

您可以使用GGPLOT命令来调整颜色:

plot_models(fit1, fit2, fit3, fit4, fit5, fit6, fit7, fit8, fit9, std.est = "std2") +
  scale_color_manual(values = c("mpg.1" = "dodgerblue", 
                                "mpg.2" = "dodgerblue3", 
                                "mpg.3" = "blue",
                                "hp.4" = "yellow",
                                "hp.5" = "yellow2",
                                "hp.6" = "gold2",
                                "cyl.7" = "chartreuse", 
                                "cyl.8" = "springgreen4", 
                                "cyl.9" = "forestgreen"))

如您所见,子类型之间的区别不是很好。

You can use ggplot commands to adjust the colors:

plot_models(fit1, fit2, fit3, fit4, fit5, fit6, fit7, fit8, fit9, std.est = "std2") +
  scale_color_manual(values = c("mpg.1" = "dodgerblue", 
                                "mpg.2" = "dodgerblue3", 
                                "mpg.3" = "blue",
                                "hp.4" = "yellow",
                                "hp.5" = "yellow2",
                                "hp.6" = "gold2",
                                "cyl.7" = "chartreuse", 
                                "cyl.8" = "springgreen4", 
                                "cyl.9" = "forestgreen"))

As you can see, the distinction between the subtypes is not very good.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文