Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Error in plot.new() : plot region too large" while plotting 4 maps(2*2) inside one layout/faced/grid using R

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.

like image 621
user2946704 Avatar asked Feb 14 '23 15:02

user2946704


1 Answers

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.
like image 199
lodebari Avatar answered Feb 16 '23 08:02

lodebari