Error in plot.new() : figure margins too large
Posted Data+Science+Insight
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Error in plot.new() : figure margins too large相关的知识,希望对你有一定的参考价值。
Error in plot.new() : figure margins too large
目录
Error in plot.new() : figure margins too large
#问题
拟合回归模型并计算每一个样本的dfbetas值,最佳dfbetas阈值,最后可视化每个样本对每个预测变量的影响程度;
#fit a regression model
model <- lm(mpg~disp+hp, data=mtcars)
#view model summary
summary(model)
#calculate DFBETAS for each observation in the model
dfbetas <- as.data.frame(dfbetas(model))
#display DFBETAS for each observation
dfbetas
#find number of observations
n <- nrow(mtcars)
#calculate DFBETAS threshold value
thresh <- 2/sqrt(n)
thresh
#specify 2 rows and 1 column in plotting region
#dev.off()
#par(mar = c(1, 1, 1, 1))
par(mfrow=c(2,1))
#plot DFBETAS for disp with threshold lines
plot(dfbetas$disp, type='h')
abline(h = thresh, lty = 2)
abline(h = -thresh, lty = 2)
#plot DFBETAS for hp with threshold lines
plot(dfbetas$hp, type='h')
abline(h = thresh, lty = 2)
abline(h = -thresh, lty = 2)
#解决
par(mar = c(1, 1, 1, 1))
#fit a regression model
model <- lm(mpg~disp+hp, data=mtcars)
#view model summary
summary(model)
#calculate DFBETAS for each observation in the model
dfbetas <- as.data.frame(dfbetas(model))
#display DFBETAS for each observation
dfbetas
#find number of observations
n <- nrow(mtcars)
#calculate DFBETAS threshold value
thresh <- 2/sqrt(n)
thresh
#specify 2 rows and 1 column in plotting region
#dev.off()
par(mar = c(1, 1, 1, 1))
par(mfrow=c(2,1))
#plot DFBETAS for disp with threshold lines
plot(dfbetas$disp, type='h')
abline(h = thresh, lty = 2)
abline(h = -thresh, lty = 2)
#plot DFBETAS for hp with threshold lines
plot(dfbetas$hp, type='h')
abline(h = thresh, lty = 2)
abline(h = -thresh, lty = 2)
完整错误:
> par(mfrow=c(2,1))
>
> #plot DFBETAS for disp with threshold lines
> plot(dfbetas$disp, type='h')
Error in plot.new() : figure margins too large
> abline(h = thresh, lty = 2)
Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) :
plot.new has not been called yet
> abline(h = -thresh, lty = 2)
Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) :
plot.new has not been called yet
>
> #plot DFBETAS for hp with threshold lines
> plot(dfbetas$hp, type='h')
Error in plot.new() : figure margins too large
> abline(h = thresh, lty = 2)
Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) :
plot.new has not been called yet
> abline(h = -thresh, lty = 2)
Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) :
plot.new has not been called yet
参考:R
参考:How to Calculate DFBETAS in R
参考:How to Fix: error in plot.new() : figure margins too large
参考:Error in plot.new() : figure margins too large, Scatter plot
以上是关于Error in plot.new() : figure margins too large的主要内容,如果未能解决你的问题,请参考以下文章
R 报错Error in plot.new() : figure margins too large
# Error in colSums(iris) : ‘x‘ must be numeric,# Error in rowSums(iris) : ‘x‘ must be numeric