4

Using R Studio when trying to plot an xts object using chartSeries() the following error pop's up:

Error in plot.new() : figure margins too large

However when plotting it directly in R there is no problem with the margins size.

How can I correct the margins size for R Studio.

Note: the time series has more than 10,000 observations/entries

Thanks

Daniel
  • 41
  • 1
  • 1
  • 3
  • Suspect its not really an R issue... Just increase the size of the plot panel in Rstudio or change the graphics device eg. http://www.astrostatistics.psu.edu/datasets/R/html/grDevices/html/windows.html – user5219763 Mar 30 '16 at 16:42
  • 2
    Possible duplicate of [Error in plot.new() : figure margins too large in R](http://stackoverflow.com/questions/12766166/error-in-plot-new-figure-margins-too-large-in-r) – user5219763 Mar 30 '16 at 16:45
  • Please provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) to demonstrate what you are trying to plot. Because this also means a [minimal example](http://stackoverflow.com/help/mcve), I recommend you attempt to either (a) reduce your data set to find a good breaking point (for your own troubleshooting), or (b) try it with a short-code randomly-generated dataset. – r2evans Mar 30 '16 at 16:45
  • Unsure if this is what happened to you, but I had my plot window too small in RStudio and enlarged it, error goes away. – egon Dec 09 '19 at 23:32

3 Answers3

10

write this three lines:

graphics.off() par("mar") par(mar=c(1,1,1,1))

Hiren
  • 1,427
  • 1
  • 18
  • 35
5

This sometimes happens in RStudio. In order to solve it you can use any one of the following approach.

  1. May be your "Plots" pane is too small. Just zoom it and see.
  2. "Clear All Plots" in Plots pane and see.
  3. Run "graphics.off()" in the console and see.
alex
  • 5,467
  • 4
  • 33
  • 43
Mahan
  • 371
  • 1
  • 4
  • 11
0
####################
#                  #
#    Exercise 1    #
#                  #
####################
auto <- read.csv("D:/forecasting-tutorial/vehicle.csv")
plot(auto$sales,
     type = "n",
     ylim = c(0, 5000),
     ylab = "Sales, '000 units",
     xlab = "Period",
     main = "US light vehicle sales in 1976-2016")
lines(auto$sales)

#plot of chunk forecasting-part-4

####################
#                  #
#    Exercise 2    #
#                  #
####################
auto$trend <- seq(1:nrow(auto))
auto$income_lag <- c(NA, auto$income[1:nrow(auto)-1])
auto$unemp_lag <- c(NA, auto$unemp[1:nrow(auto)-1])
auto$rate_lag <- c(NA, auto$rate[1:nrow(auto)-1])

####################
#                  #
#    Exercise 3    #
#                  #
####################
regressions_result <- regsubsets(sales ~ ., data = auto)
plot(regressions_result, col = colorRampPalette(c("darkgreen", "grey"))(10))
plot(regressions_result, col = colorRampPalette(c("darkgreen", "grey"))(10))
Error in plot.new() : figure margins too large`enter code here`
  • How to solve, Error in plot.new() : figure margins too large`enter code here`, – bambangpe Oct 06 '17 at 03:32
  • graphics.off() par("mar") par(mar=c(1,1,1,1)), still can not run the plot(regressions_result, col = colorRampPalette(c("darkgreen", "grey"))(10)), in my laptop par("mar") [1] 7.1 5.1 6.1 3.1 – bambangpe Oct 06 '17 at 03:33