简体   繁体   English

R 如何以不同方式排列诊断图

[英]R how to arrange diagnostic plots differently

I'm trying to figure out how I can arrange diagnostic plots differently using the plot() function.我试图弄清楚如何使用 plot() function 以不同方式排列诊断图。 Here is my code:这是我的代码:

mtcars_linear_model <- lm(mpg ~ wt, mtcars)

plot(mtcars_linear_model)

It will print these four plots in my console.它将在我的控制台中打印这四个图。

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

Is there a way to arrange them using ggarrange?有没有办法使用 ggarrange 来安排它们? I can't seem to print one of them at a time.我似乎无法一次打印其中一个。 I thought maybe I could call the index with the plot() function to get the plots one at a time but it doesn't work:我想也许我可以用 plot() function 调用索引来一次获取一个图,但它不起作用:

plot(mtcars_linear_model)[1]

I want to use each plot separately in ggarrange like this:我想像这样在 ggarrange 中分别使用每个 plot :

ggarrange(residuals_vs_fitted, normal_qq, scale_location, residuals_vs_leverage)

So that I could get one image with a 2x2 grid of these four diagnostic plots.这样我就可以得到一张包含这四个诊断图的 2x2 网格的图像。

Using R base使用R底座

x11()
par(mfrow=c(2,2))
plot(mtcars_linear_model)

This will produce:这将产生:

在此处输入图像描述

You can reset plot params by par(mfrow=c(1,1))您可以通过par(mfrow=c(1,1))重置 plot 参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM