gpt4 book ai didi

r - 如何获得R中回归分析生成的四个图?

转载 作者:行者123 更新时间:2023-12-03 04:58:11 27 4
gpt4 key购买 nike

如何不使用控制台/提示符( Hit <Return> to see next plot: )从回归分析中生成生成的四个图表(一个与另一个分开/一次一个)?

if(!require("truncnorm")) install.packages("truncnorm") ; library(truncnorm)


FACTORA <- c(0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0)
FACTORB <- c(0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0)
FACTORC <- c(0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0)
FACTORD <- c(0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0)
FACTORE <- c(0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0)

planDOE <- data.frame(FACTORA,
FACTORB,
FACTORC,
FACTORD,
FACTORE,
rtruncnorm(n=32, a=0, mean=61.16, sd=31.32))

rg <- lm(planDOE)
plot(rg)

我尝试了以下方法但没有成功(在询问参数命令中使用 true 或 false ask )。

plot(rg)
par(ask=TRUE)

#

par(ask=FALSE)
plot(rg)

#

plot(rg, ask = FALSE)

#

par(mfrow=c(2,2))
plot(rg)
# In one image it can put together the graphic information.

#

png('test2.png', units="in", width=13, height=7, res=300)
plot(rg)
dev.off()

通过最后一种方式,我意识到可以单独获取图,但只保存残差图。

答案:

plot(rg, which = 1)
plot(rg, which = 2)
#...

最佳答案

设置 par(mfrow = params)。使用 mtcars,这是一个例子。之后您可以将绘图保存为 .png 文件

rg <- lm(mpg~cyl + wt, data = mtcars)

par(mfrow=c(2,2))
plot(rg)

关于r - 如何获得R中回归分析生成的四个图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50459433/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com