简体   繁体   中英

R how to arrange diagnostic plots differently

I'm trying to figure out how I can arrange diagnostic plots differently using the 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? 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(mtcars_linear_model)[1]

I want to use each plot separately in ggarrange like this:

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.

Using R base

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

This will produce:

在此处输入图像描述

You can reset plot params by par(mfrow=c(1,1))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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