title: Multiple plots using loops in R
body: <p>I'm still trying to get my head around using loops to plot in R. I would like to plot (any plot to visualise the data will do) columns z_1 against z_2 in the data frame below according to the different names in column x_1.</p>
  
  <pre><code>x_1 &lt;- c("A1", "A1","A1", "B10", "B10", "B10","B10", "C100", "C100", "C100")
  
  
  z_1 &lt;- rnorm(10, 70) 
  
  z_2 &lt;- rnorm(10, 1.7)
  
  A &lt;- data.frame(x_1, z_1, z_2)
  </code></pre>
  
  <p>As such, I would like to end up with three different plots; one for category A1, one for B10 and another for C100. I can do this using three different codes but I would like to be able to use a loop or any other single code to execute all three plots on the same page. In reality, I have a large dataset (4,000 rows) and would like to plot a couple of IDs on a page (say 5 on a page). </p>
  
  <p>I hope this makes sense. Thanks for your help. </p>
  
  <p>Here's my attempt at plotting them individually:</p>
  
  <p>for A1:</p>
  
  <pre><code>data_A1 &lt;- A[which(A$x_1 == "A1"), ]
  plot(data_A1$z_2, data_A1$z_1)
  </code></pre>
  
  <p>I also tried something like this but getting error messages</p>
  
  <pre><code>for ( i in A$x_1[[i]]){
  
  plot(A[which(A$x_1==A$x_1[[i]]), ], aspect = 1)
  }
  </code></pre>