title: Loops for making maps in r
body: <p>I have a data frame with 500 species and 25,000 point locality observations of the various species. I would like to make individual species point maps, each point on the map is an occurrence of the species. Because there are so many maps to make, I need to do this in a loop. This is what I have so far. </p>
  
  <pre><code>#loop for making species map 1.1
  species &lt;- levels(raw$SpCode)
  for(i in 1:length(species))  
              {
              #open the file for writing
               pdf(species[i], file=".pdf", width=5, height=4)
               plot (wrld_simpl, xlim=c(-100,-55), ylim=c(23,63), axes=TRUE, col='light grey')
               box() #adds box around map
               title(main=species[i]) #adds main title to map which should be the species name associated with the data
               points(raw, species[i]$longitude, species[i]$latittude, col='black', pch=21, bg="red", cex=0.85)
               dev.off()
               }
  </code></pre>
  
  <p>The main error output I am getting is: </p>
  
  <pre><code>“Error in species[i]$longitude : $ operator is invalid for atomic vectors
  In addition: Warning message:
  ‘mode(onefile)’ differs between new and previous==&gt; NOT changing ‘onefile’"
  </code></pre>
  
  <p>Any advice on how to move forward with this would help. I am using the maptools package to try to make these maps. </p>
  
  <p>Cheers, 
  Israel </p>