title: lapply, specifiying and plotting multiple variables from a data frame
body: <p>I'm not having any success combining lapply, substitute, print, plot, and list in a function statement.  Can someone direct me to a way to revise this code?  I'd like to:</p>
  
  <ol>
  <li>automate plotting some but not all fields in a data frame vs. the first field in the df</li>
  <li>specify the fields to plot</li>
  <li>write the result to a file</li>
  </ol>
  
  <p>The fields are numeric. Thanks.</p>
  
  <pre><code>brg&lt;-as.data.frame(sqlFetch(channel,"Bearing"))               
  is.data.frame(brg)                                            
  
  varlist&lt;-names(brg)[c(6,8,10,12)]                             
  varlist                                                       
  pdf(file="brg%d.pdf")                                         
  figures&lt;-lapply(varlist,function(x) {                         
  print(plot(substitute(brg[c(1,i)], (list(i = as.name(x))))))
  })  
  </code></pre>
  
  <p>update:  Thanks for the comments. Here are two working versions of this code with axis lables (df read from SQL Server as written): </p>
  
  <pre><code>     #vers. 1
       brg&lt;-as.data.frame(sqlFetch(channel,"Bearing"))
       is.data.frame(brg)
       dim(brg)
       head(brg)
       names(brg)&lt;-tolower(names(brg))
       names(brg)
       varlist&lt;-names(brg)[c(6,8,10,12)]
       varlist
       pdf(file="brgd.pdf")
       for (x in varlist) plot(brg[,1],brg[,x], xlab=names(brg[1]),ylab=as.name             (x))           
       dev.off()
  
       #vers. 2
       brg&lt;-as.data.frame(sqlFetch(channel,"Bearing"))
       is.data.frame(brg) 
       dim(brg)
       head(brg)
       names(brg)&lt;-tolower(names(brg))
       names(brg)
       varlist&lt;-names(brg)[c(6,8,10,12)]
       varlist
       pdf(file="brg1.pdf")
       figures&lt;-lapply(varlist,function(x) {
  
       (plot(brg[,1],brg[,x], ylab=as.name(x)))
       })
       dev.off()                                                 
  </code></pre>