title: Creating a for loop to implement ggplot2 with a series of variables. Consider everything as a missing value
body: <p>I'm trying to develop a loop to plot every column from a dataset called <code>chr</code>, with the code I'm using, a for loop, conditioned by some criteria, to save plots in a list</p>
  <pre><code>desired_length &lt;- 8
  plot_list &lt;- vector(mode = &quot;list&quot;, length = desired_length)
  for(i in 3:10) {
    {lot_list[[i-2]] &lt;- ggplot(chr) +
      geom_point(data = chr, aes(x = chr[,1], y = chr[,i], color = ponto),
                 size = 2) +
      geom_hline(yintercept = as.double(cla[1,i-1]), size = 2, linetype = &quot;dashed&quot;, color = &quot;black&quot;) +
      ylim(0,max(chr[,i], na.rm = TRUE)) +
      labs(title = glue(&quot;Resultados analíticos no corpo receptor do empto para {(colnames(chr))[i]}&quot;),
           subtitle = glue(&quot;Padrão de c3 ={cla[,i-1]} mg/L&quot;), y = glue(&quot;{(colnames(chr))[i]} (mg/L)&quot;), x = &quot;Período de análise&quot;, caption = glue(&quot;Número de amostras = {sum(!is.na(chr[,i]))}&quot;)) +
      theme_minimal()
    }
  }
  
  </code></pre>
  <p>if I save if manually, like, for example:</p>
  <pre><code>
  plot_list[[1]] &lt;- ggplot(chr) +
    geom_point(data = chr, aes(x = chr[,1], y = chr[,3], color = ponto),
               size = 2) + ...
  
  </code></pre>
  <p>it plots perfectly when i run</p>
  <pre><code>plot_list[[1]]
  </code></pre>
  <p><img src="https://i.stack.imgur.com/lC782.jpg" alt="plot as expected" /></p>
  <p>but when i run the plot after running the loop, also with plot_list[<a href="https://i.stack.imgur.com/lC782.jpg" rel="nofollow noreferrer">1</a>], it displays that all values are missing and only shows this plot, with a this Warning message: Removed 142 rows containing missing values (geom_point).</p>
  <p><img src="https://i.stack.imgur.com/aWch8.jpg" alt="plot with missing values" /></p>
  <p>What could've gone wrong? thanks in advance for helping me</p>