DATA MINING
Desktop Survival Guide by Graham Williams |
|||||
R provides a set of tools for reading geographic (map) data, particularly ESRI http://en.wikipedia.org/wiki/Shapefileshapefiles, and plotting and manipulating such data. Maps for many countries are available, particularly the US, Europe, and New Zealand. Limited Australian map data is also freely available.
download.file("http://www.vdstech.com/mapdata/australia.zip", "australia.zip") system("unzip australia.zip; rm australia.zip") |
The data can be read in with readShapePoly and displayed with plot. Australia has a few outlying islands which we crop from the main focus of the map here using xlim and ylim.
library(maptools) aus <- readShapePoly("australia.shp") plot(aus, lwd=2, border="grey", xlim=c(115,155), ylim=c(-35,-20)) dev.off() |
The class of the resulting object (aus) is SpatialPolygonsDataFrame. Such an object has a collection of slots. For example, the data slot includes meta information about the region recorded in the data frame.
> aus@data FIPS_ADMIN GMI_ADMIN ADMIN_NAME FIPS_CNTRY CNTRY_NAME 0 AS01 AUS-ACT Australian Capital Territory AS Australia 1 AS02 AUS-NSW New South Wales AS Australia 2 AS03 AUS-NTR Northern Territory AS Australia 3 AS04 AUS-QNS Queensland AS Australia 4 AS05 AUS-SAS South Australia AS Australia 5 AS06 AUS-TSM Tasmania AS Australia 6 AS07 AUS-VCT Victoria AS Australia 7 AS08 AUS-WAS Western Australia AS Australia REGION CONTINENT POP_ADMIN SQKM_ADMIN SQMI_ADMIN TYPE_ENG 0 Australia/New Zealand Australia 292475 2342.295 904.36 Territory 1 Australia/New Zealand Australia 6338919 803110.812 310081.09 State 2 Australia/New Zealand Australia 161294 1352365.000 522148.09 Territory 3 Australia/New Zealand Australia 3107362 1733475.000 669294.69 State 4 Australia/New Zealand Australia 1445153 985308.500 380427.59 State 5 Australia/New Zealand Australia 472122 68131.477 26305.56 State 6 Australia/New Zealand Australia 4354611 227781.406 87946.40 State 7 Australia/New Zealand Australia 1655588 2533628.000 978233.81 State TYPE_LOC 0 Territory 1 State 2 Territory 3 State 4 State 5 State 6 State 7 State |
The bounding box of the plot is available using bbox.
> bbox(aus) min max r1 112.90721 159.10190 r2 -54.75389 -10.05139 |