title: Create plots in a loop using ggplot2
body: <p>I have to generate 250 plots with the same view.</p>
  
  <p>My example data set:</p>
  
  <pre><code>df &lt;- data.frame(name = c("john","alex","mike","dennis","alex"),
               expenses = c("10","12","15","8","2"),
               type = c("food","rent","rent","food","food"))
  </code></pre>
  
  <p>I would like bar plots with the expenses for every name in a single plot. The plot for "alex" will look like:</p>
  
  <pre><code>selected.name &lt;- "alex"
  df1 &lt;- subset(df, name == selected.name)
  ggplot(data = df1, aes(type, expenses)) + geom_bar()
  </code></pre>
  
  <p>Now I want to use a loop that plots the same plot for every name in the df. I have tried to use a for loop that runs the plot code above as a source file. But I can't pass the name variable to the source file so that it plots the graph for every name. Now I only get one graph out of the for loop.</p>