4
votes

I am new to R and trying to plot airline network graphs using Map in R. I am stuck at a point where I want to plot 4 different plots in a panel/ facet/grid. i am getting an error as follows :

Error in plot.new() : plot region too large

Sample Code till now :

   get( getOption( "device" ) )()


   par( mfrow = c( 2, 2 ) ) // 2 * 2 matrix intended 


   map("world", col="#191919", fill=TRUE, bg="#111111", lwd=0.05, xlim=xlim, ylim=ylim)

//sample map without any network lines ..

PS : This is not a duplicate post. I saw some posts with figure margins too large in R. But this is something different as per my understanding.

2
Generally, you have to call "plot" 4 times to get a 2x2 figure. Can you provide a reproducible example?Roman Luštrik
something of this sort .. "statmethods.net/advgraphs/images/layout1.jpg".. but instead of 4 different types of plots all 4 would be different maps ..user2946704
Are you using an IDE? How large is your plot window?Roman Luštrik
Yes I am using R Studio. Plot window is like 1/4th of the total screen size.user2946704
Enlarge the plotting device or see if plotting in "raw R" produces the same error.Roman Luštrik

2 Answers

6
votes

This is a problem linked to RStudio (see here). It occurs when the Plots pane area is smaller than the plot area.

Solutions:

  1. Enlarging the Plots pane (thanks to @Roman Luštrik for the suggestion). However it doesn't always work. Sometimes the plot area is still greater than the Plots pane area, even after increasing it.
  2. Using "raw R" as suggested by @Roman Luštrik (thanks again). It solves the problem completely since R adapts the plot size to the plotting window.
  3. Plotting to a file also solves the problem when using RStudio.
2
votes

run dev.off() before you plot your data