title: How to create new object names based on vector?
body: <p>I'm trying to knit a document that creates ggplots and stores them as named objects, allowing me to print and discuss them at will throughout the document.</p>
  
  <p>So far I've tried using this loop formula. It works great for my actual dataset, which has 120 variables. Today I want to look at some of them, tomorrow I may want to look at others. This lets me specify which ones I want.</p>
  
  <pre class="lang-r prettyprint-override"><code># Generate a data frame with 100 rows and four factor columns.
  mydata &lt;- data.frame(agegroup = as.factor(sample.int(10,100,replace = TRUE)),
                       incomegroup = as.factor(sample.int(10,100,replace = TRUE)),
                       othergroup = as.factor(sample.int(10,100,replace = TRUE)),
                       bygroup = as.factor(sample.int(3,100,replace=TRUE)))
  
  # Choose the columns we're interested in
  vars &lt;- c("agegroup","incomegroup","othergroup")
  
  # Make a list of names for the plots I want to create
  plotnames &lt;- c("ageplot","incomeplot","otherplot")
  
  for (i in 1:3){
  
  plotnames[i] &lt;- ggplot(mydata, aes(bygroup, fill = mydata[,vars[i]])) + 
    geom_bar(position = "fill") + labs(title= vars[i], x="bygroup", y="") + 
    scale_fill_discrete(name= vars[i])
  
  
  }
  </code></pre>
  
  <p>Obviously this doesn't work. I want R to summon a string from the plotnames list and use it as the name for a new object. How can I get this done?</p>
  
  <p>EDIT: Changed plot to ggplot. This is what I'm really trying to do in my work. I tried to use base r to make the question shorter.</p>