0

I need help with R:

using flights dataset from the nycflights13 package

https://github.com/hadley/nycflights13

I need to produce a bar chart of the origin variable but get an error

tab_orig <- sort(table(flights$origin))
> tab_orig

   LGA    JFK    EWR 
104662 111279 120835 

> barplot(tab_orig)
Error in plot.new() : figure margins too large
  • `barplot(tab_orig)` works fine for me. You can have a look here - https://stackoverflow.com/questions/23050928/error-in-plot-new-figure-margins-too-large-scatter-plot – Ronak Shah Oct 18 '20 at 06:23

1 Answers1

0

There can be two reasons that you are not able to see the bar plot.

  1. Your viewer window is too small for it to contain the graph. In that case just drag the viewer window on the right corner of your RStudio and make it big enough for it to incorporate your graph.

  2. The next may be due to data. It maybe that your data is too big so machine is not bale to assign margins for the data automatically. You will have to re-assign margin parameters.

Before that, you can check margin using par("mar"). You should get :

5.1 4.1 4.1 2.1

You can use par(mar=c(1,1,1,1)) and invoke dev.off() to make R open your plot in a separate window.

You code will look something like this:

par(mar=c(1,1,1,1))
pdf('filename.pdf')
barplot(tab_orig, main="Graph title",xlab="X-axis legend", ylab="Y-axis legend", pch=20, cex=2)
dev.off()

Here, par: sets or adjusts plotting parameters. mar: A numeric vector of length 4, which sets the margin sizes in the following order: bottom, left, top, and right.