如何得到R中回归分析生成的四张图?
How to get the four graphs generated from the regression analysis in R?
如何不使用控制台/提示(Hit <Return> to see next plot:
)从回归分析中生成四个图形(一次与other/one分开一个)?
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)
#...
设置参数(mfrow = 参数)。使用 mtcars,这里有一个例子。之后您可以将绘图另存为 .png 文件
rg <- lm(mpg~cyl + wt, data = mtcars)
par(mfrow=c(2,2))
plot(rg)
如果你这样做了,你真的可以看到这个?plot.lm
mod <- lm(1:10 ~ rnorm(10))
现在您可以在 plot.lm
中指定 which
参数来单独绘制每个图。如,
png('plot_1.png', units="in", width=13, height=7, res=300)
plot(mod, which = 1)
dev.off()
png('plot_2.png', units="in", width=13, height=7, res=300)
plot(mod, which = 2)
dev.off()
plot(mod, which = 3)
plot(mod, which = 5)
如果您使用 plot(mod)
.
,这些将绘制您通常会得到的数字
当然,你可以在每个情节之后保存,或者只保存你喜欢的情节。
注意:我没有使用which = 4
。
如何不使用控制台/提示(Hit <Return> to see next plot:
)从回归分析中生成四个图形(一次与other/one分开一个)?
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)
#...
设置参数(mfrow = 参数)。使用 mtcars,这里有一个例子。之后您可以将绘图另存为 .png 文件
rg <- lm(mpg~cyl + wt, data = mtcars)
par(mfrow=c(2,2))
plot(rg)
如果你这样做了,你真的可以看到这个?plot.lm
mod <- lm(1:10 ~ rnorm(10))
现在您可以在 plot.lm
中指定 which
参数来单独绘制每个图。如,
png('plot_1.png', units="in", width=13, height=7, res=300)
plot(mod, which = 1)
dev.off()
png('plot_2.png', units="in", width=13, height=7, res=300)
plot(mod, which = 2)
dev.off()
plot(mod, which = 3)
plot(mod, which = 5)
如果您使用 plot(mod)
.
当然,你可以在每个情节之后保存,或者只保存你喜欢的情节。
注意:我没有使用which = 4
。