4
votes

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

3
Suspect its not really an R issue... Just increase the size of the plot panel in Rstudio or change the graphics device eg. astrostatistics.psu.edu/datasets/R/html/grDevices/html/…user5219763
Please provide a reproducible example to demonstrate what you are trying to plot. Because this also means a minimal example, 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
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

3 Answers

10
votes

write this three lines:

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

5
votes

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.
0
votes
####################
#                  #
#    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`