title: ggave() Error: Unknown input R
body: <p>I am having trouble with ggsave() from the ggplot2 library. I wrote a function that I pass arguments to, and that is supposed to produce and then save the results with ggsave(). </p>
  
  <p>Here is some example data and code to reproduce the error:</p>
  
  <pre><code>example.df.1 &lt;- data.frame(matrix(1:100, nrow = 20, ncol = 5))
  colnames(example.df.1) &lt;- c("var1", "var2", "var3", "var4", "var5")
  rownames(example.df.1) &lt;- c("A", "B", "C", "D", "E", "F", "G", "H", 
                              "I", "J", "K", "L", "M", "N", "O", "P",
                              "Q", "R", "S", "T")
  
  example.df.2 &lt;- data.frame(matrix(ncol = 2, nrow = 24))
  example.df.2[,1] &lt;- c("A", "B", "C", "D", "E", "F", "G", "H", 
                              "I", "J", "K", "L", "M", "N", "O", "P",
                              "Q", "R", "S", "T", "U", "V", "W", "X")
  
  example.df.2[,2] &lt;- rnorm(24, 10, 2)                            
  
  problematic_func &lt;- function(data1, col, title, var, data2)  {
      # only include rows without missing values
      loc1 &lt;- subset(data1, rowSums(is.na(data1)) == 0)
  
      loc1 &lt;- cbind(loc1, rank(-as.data.frame(loc1[,1]), ties.method = "first"))
  
      # reduce data2 to only those rows that correspond to rows in data1
      loc2 &lt;- data2[data2[,1] %in% rownames(loc1),]
  
      # order loc2
      loc2.ordered &lt;- loc2[order(loc2[,1]),]
  
      # correlation between loc1 and loc2.ordered
      corr &lt;- cor(loc1[,1], loc2.ordered[,2])
  
      # creating the plot
      i &lt;- ggplot(loc1, aes_q(x = loc1[,1], y = loc2.ordered))
      i &lt;- i + geom_point(colour = col, size = 4)
      i &lt;- i + ggtitle(title)
      i &lt;- i + xlab(var)
      i &lt;- i + ylab("y-axis")
      i &lt;- i + coord_cartesian(xlim = c(0, max(loc1[,1])),
          ylim = c(0, max(loc2.ordered[,2])*1.2))
      i &lt;- i + annotate("text", x = max(loc1[,1])*.5, y = 1,
          label = paste("Correlation coef: ", as.character(corr)), size = 3)
  
      # saving the plot - this is where the error occurs according
      # to the debugger   
      ggsave(filename = paste("my_example_plot_", var, ".png", sep = ""),
          plot = i, device = png, width = 625, height = 625, limitsize = FALSE)
  }
  
  for (i in 1:ncol(example.df.1)) {
      sv &lt;- as.data.frame(example.df.1[,i])
      rownames(sv) &lt;- rownames(example.df.1)
      problematic_func(sv, "orange", colnames(example.df.1[i]),
          colnames(example.df.1[i]), data2 = example.df.2)
  }
  </code></pre>
  
  <p>Edit: Sorry, I forgot to add the error I get:</p>
  
  <blockquote>
    <p>Error in FUN(X[[2L]], ...) : Unknown input:data.frame</p>
  </blockquote>