I have a shapefile showing remote areas in Australia, obtained from the Australian Bureau of Statistics:
http://www.abs.gov.au/AUSSTATS/[email protected]/DetailsPage/1270.0.55.005July%202011?OpenDocument
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.
I have read in the shapefile and added colour information to the data
slot:
ra <- readShapeSpatial("RA_2011_AUST", delete_null_obj = TRUE)
ra@data$COLOUR <- "#FFFFFF"
ra@data$COLOUR[(as.numeric(as.character(ra@data$RA_CODE11)) %% 10) == 0] <- "#006837"
ra@data$COLOUR[(as.numeric(as.character(ra@data$RA_CODE11)) %% 10) == 1] <- "#31A354"
ra@data$COLOUR[(as.numeric(as.character(ra@data$RA_CODE11)) %% 10) == 2] <- "#78C679"
ra@data$COLOUR[(as.numeric(as.character(ra@data$RA_CODE11)) %% 10) == 3] <- "#C2E699"
ra@data$COLOUR[(as.numeric(as.character(ra@data$RA_CODE11)) %% 10) == 4] <- "#FFFFCC"
The only thing left for me to do is plot the map! This is where I get stuck...
ra@polygons
is a list of 35 polygons, each of which has a slot ID
which is an index to the data frame ra@data
. So all I have to do is tell plot()
to find the colour in ra@data$COLOUR[ID]
. Well, not quite. Each of the 35 polygons (class "Polygons") has its own list of polygons (class "Polygon"); in total there are 6902 polygons!!!
My understanding of plot()
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?
That would be easy enough if the polygons were plotted in order, but they aren't. Each of the 35 Polygons has a slot plotOrder
which is an integer vector, so the colour vector will, presumably, have to be ordered by the values in each of these vectors.
At this point this all seems a bit too complex. Am I completely off track here?
Thanks for your advice!