[R] Plot layout help?

rkevinburton at charter.net rkevinburton at charter.net
Sat Dec 27 20:39:56 CET 2008


I am trying to visualize a dataset and I think I almost have it but I need some assistance.

THe following commands:

library("forecast")
library("expsmooth")

plot(carparts[,2001:2010],main="Monthly car part sales",xlab="Year")

The last plot command puts 10 graphs on one page with the y axis labeled with the column name (the carparts data set is a matrix). The plot seems to removed all margins and amkes it so that earch individual plot on the page has sufficient spce and reslution. Now I want to do something to the data and replot it. The specific sommands:

  fitsubmatrix <- function(o, r)
  {
    def.par <- par(no.readonly = TRUE) # save default, for resetting...
    on.exit(par(def.par))
  
    layout(matrix(c(1,2, 3,4, 5,6, 7,8, 9,10), nc=2))
  
    for(.index in r)
    {
        fit <- ets(o[,.index])
        fc <- forecast(fit, h = 8)
        plot(fc)
    }
  }


The result is 10 plots on a page but the margins between each plot are such that this is no room fo the plot and it looks "squished". I am conviced that this has more to do with the layout of the plot than the commands that I used to generate the plot (in the forecast packate). I think this is a plot layout question not a forecast question.

Any ideeas on how I can layout the second plot like the automatic layout of the first?

Thank you.

Kevin



More information about the R-help mailing list