title: R - stuck with plot() - Colouring shapefile polygons based upon a slot value
body: <p>I have a shapefile showing remote areas in Australia, obtained from the Australian Bureau of Statistics:</p>
  
  <p><a href="http://www.abs.gov.au/AUSSTATS/abs@.nsf/DetailsPage/1270.0.55.005July%202011?OpenDocument">http://www.abs.gov.au/AUSSTATS/abs@.nsf/DetailsPage/1270.0.55.005July%202011?OpenDocument</a></p>
  
  <p>At the same URL is a PDF "ASGS Remoteness Structure Edition 2011 PDF Maps" - I am trying to reproduce the first map from this PDF document.</p>
  
  <p>I have read in the shapefile and added colour information to the <code>data</code> slot:</p>
  
  <pre><code>ra &lt;- readShapeSpatial("RA_2011_AUST", delete_null_obj = TRUE)
  ra@data$COLOUR &lt;- "#FFFFFF"
  ra@data$COLOUR[(as.numeric(as.character(ra@data$RA_CODE11)) %% 10) == 0] &lt;- "#006837"
  ra@data$COLOUR[(as.numeric(as.character(ra@data$RA_CODE11)) %% 10) == 1] &lt;- "#31A354"
  ra@data$COLOUR[(as.numeric(as.character(ra@data$RA_CODE11)) %% 10) == 2] &lt;- "#78C679"
  ra@data$COLOUR[(as.numeric(as.character(ra@data$RA_CODE11)) %% 10) == 3] &lt;- "#C2E699"
  ra@data$COLOUR[(as.numeric(as.character(ra@data$RA_CODE11)) %% 10) == 4] &lt;- "#FFFFCC"
  </code></pre>
  
  <p>The only thing left for me to do is plot the map! This is where I get stuck...</p>
  
  <p><code>ra@polygons</code> is a list of 35 polygons, each of which has a slot <code>ID</code> which is an index to the data frame <code>ra@data</code>. So all I have to do is tell <code>plot()</code> to find the colour in <code>ra@data$COLOUR[ID]</code>. Well, not quite. Each of the 35 polygons (class "Polygons") has its own list of polygons (class "Polygon"); in total there are 6902 polygons!!!</p>
  
  <p>My understanding of <code>plot()</code> is that I have to pass it a vector of colours in the same order as the polygons will be plotted. Therefore I believe I will have to create a vector of length 6902 with each element holding the colour value for the associated polygon. How am I doing so far?</p>
  
  <p>That would be easy enough if the polygons were plotted in order, but they aren't. Each of the 35 Polygons has a slot <code>plotOrder</code> which is an integer vector, so the colour vector will, presumably, have to be ordered by the values in each of these vectors.</p>
  
  <p>At this point this all seems a bit too complex. Am I completely off track here?</p>
  
  <p>Thanks for your advice!</p>