DATA MINING
Desktop Survival Guide by Graham Williams |
|||||
Map displays often provide further insights into patterns that vary according to region. In this plot we illustrate some basic colouring of a map. This can be used to translate a variable into a colour which is then plot for the state. We use the rainbow function to generate the bright colours to use to colour the states.
library(maptools) aus <- readShapePoly("australia.shp") plot(aus, lwd=2, border="grey", xlim=c(115,155), ylim=c(-35,-20)) colours <- rainbow(8) # Must be a better way than this.... nsw <- aus; nsw@plotOrder <- as.integer(c(2)); plot(nsw,col=colours[2],add=TRUE) act <- aus; act@plotOrder <- as.integer(c(1)); plot(act,col=colours[1],add=TRUE) nt <- aus; nt@plotOrder <- as.integer(c(3)); plot(nt, col=colours[3],add=TRUE) qld <- aus; qld@plotOrder <- as.integer(c(4)); plot(qld,col=colours[4],add=TRUE) sa <- aus; sa@plotOrder <- as.integer(c(5)); plot(sa, col=colours[5],add=TRUE) tas <- aus; tas@plotOrder <- as.integer(c(6)); plot(tas,col=colours[6],add=TRUE) vic <- aus; vic@plotOrder <- as.integer(c(7)); plot(vic,col=colours[7],add=TRUE) |