[R] R help, using R to build choropleth

iverson iverson.zhou at med.govt.nz
Thu Jun 28 07:26:59 CEST 2012


Hi guys

i need some help to build choropleth.

Basically i am trying to colour regions on the map by population.

I possess the shape file of the country, and also the population data,
however, i am having trouble to create the plot, below is my code:



population=read.csv("nz2.csv")
population
names(population)

nz=readShapeSpatial((sprintf('nz-geodetic-marks',tmp_dir)))

nz$land_distr

mapnames = nz$land_distr

mapnamesnew=as.character(mapnames)

popnames =as.character(mapnamesnew)
pop =population$People

pop2=as.numeric(pop)

popdich = ifelse(pop2 < 100000, "red", "blue")
popnames.lower = tolower(popnames)

cols=popdich[match(mapnames,popnames.lower)]

plot(nz,fill=TRUE,col=cols,proj="GCS_NZGD_2000")




thanks in advance for any assistance

Kind regards

Iverson



--
View this message in context: http://r.789695.n4.nabble.com/R-help-using-R-to-build-choropleth-tp4634686.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list