title: R ggplot2 for loop
body: <p>I am trying to do to a for loop in ggplot, where I am replacing a variable that should indicate the name of existing variables that subset the data</p>
  
  <p>Here is the loop, but I get an error:</p>
  
  <pre><code>list1=c("name1","name2",...)
  list2=c("name1","name2",...)
  
  for (name in 1:2) {
  g=ggplot(data=data[paste("data$MEPS %in% list",name,sep=""),], 
       aes(x=Year, y=RR, colour=MEPS, group=MEPS 
         ))+
  geom_line()+geom_point()+scale_y_continuous(breaks=seq(0, 100, 10))+
  print(g)
  }
  </code></pre>
  
  <p>However I get the following error:</p>
  
  <pre><code>Error in seq.default(h[1], h[2], length = n) : 
  'to' cannot be NA, NaN or infinite 
  </code></pre>
  
  <p>This seemed like it should be easy -- basically I want to graph line graphs where each graph includes the information for certain areas named in <code>list1</code> or <code>list2</code> </p>
  
  <p><strong>EDIT:</strong> To clarify, what this code is "supposed" to do is produce two ggplot objects, one that has 3 lines, and the other that has 2 lines. The 3 lines represent items I wanted to show that are %in% list1, and the same thing for list2. That's whay the confusion here.</p>