error in plot with forloop

Hello everyone,

I'm new in this community, hopefully I'll write the post correctly.

I'm trying to plot 10 graphs with a for loop. I divided my screen with the function par and I got the error message Error in plot.new() : figure margins too large. I've looked it up and it seems that the problem is the dimension of the Viewer Pane, but I didn't find how to reset the size. I've tried manually by enlarging the area with no results. I've also tried to make the single plot smaller with the layout setting but unsuccessfully.

Here's the code

par(mfrow=c(5,2))
for (i in 1:10) {
plot(y.tr.ols[,i], y.te.ols[,i],pch=3)
}

where y.tr.ols and y.te.ols are two matrix of size 23x10.

I hope you can help me!

thank you in advance

Hello, welcome in the Community.

Your code becomes in general better readable when you enclose it with three backticks
(but here readability is no problem :grinning: )

I think the mai argument may help you:

set.seed(2020)
y.tr.ols = matrix(rnorm(230),nrow=23,ncol=10,byrow = T)
y.te.ols = matrix(rnorm(230),nrow=23,ncol=10,byrow = T)

par(mfrow=c(5,2),mai=c(0.1,0.1,0.1,0.1))
for (i in 1:10) {
plot(y.tr.ols[,i], y.te.ols[,i],pch=3)
}

Created on 2020-07-20 by the reprex package (v0.3.0)

Hello Han,
thank you very much! Now it works and I will keep in mind the argument mai
And thank you for the suggestion about the backticks :smile:

You are very welcome.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.