title: Extracting data used to make a smooth plot in mgcv
body: <p><a href="https://stats.stackexchange.com/questions/7795/how-to-obtain-the-values-used-in-plot-gam-in-mgcv">This thread</a> from a couple of years ago describes how to extract data used to plot the smooth components of a fitted gam model.  It works, but only when there is one smooth variable.  I've got more than one smooth variable, and unfortunately I can only extract the smooths from the last of the series.  Here is an example:</p>
  
  <pre><code>library(mgcv)
  a = rnorm(100)
  b = runif(100)
  y = a*b/(a+b)
  
  mod = gam(y~s(a)+s(b))
  summary(mod)
  
  plotData &lt;- list()
  trace(mgcv:::plot.gam, at=list(c(25,3,3,3)), 
          #this gets you to the location where plot.gam calls plot.mgcv.smooth (see ?trace)
          #plot.mgcv.smooth is the function that does the actual plotting and
          #we simply assign its main argument into the global workspace
          #so we can work with it later.....
          quote({
                      #browser()
                      plotData &lt;&lt;- c(plotData, pd[[i]])
                  }))
  plot(mod,pages=1)
  plotData
  </code></pre>
  
  <p>I'm trying to get the estimated smooth functions for both <code>a</code> and <code>b</code>, but the list <code>plotData</code> only gives me estimates for <code>b</code>.  I've looked into the guts of the <code>plot.gam</code> function, and I'm having a difficult time understanding how it works.  If anybody has already solved this problem, I'd be grateful.</p>