Hi! I posted a similar question a month ago. It helped me a lot. Maybe these answers will help you too? The last answer gives a complete example of a choropleth map.
http://r-sig-geo.2731867.n2.nabble.com/Choropleth-map-td7586627.html Good luck with it! Janka 2014-08-01 13:46 GMT+02:00 HallS <sam_l_cruicksh...@hotmail.com>: > as my data is confidential I've tried to make an anonymous data set. I > started with a shp file, and csv with a matching ID column and further > data, > including "Col_2" which is a higher level region of an aggregate of the > shapefile region. At first I merged these but it jumbled the data so I > managed to do it via match() and then gUnionCascaded. I have now retrieved > aggregated polygons without the internal boundaries, but I'm a bit lost as > to how I begin to utilise these in a choropleth map. All the instructions I > read seem out of context and being new to R I don't know how to start. I've > had a few abortive efforts with ggplot2 but all failed. Any help or > pointers > to useful articles would be appreciated. Dummy code below. > > install.packages("sp") > install.packages("rgdal") > install.packages("maptools") #read in shape files > install.packages("rgeos") # needed by maptools > install.packages("RColorBrewer") > install.packages("scales") > install.packages("gridExtra") > > library("sp") > library("rgdal") > library("maptools") > library("ggplot2") > library("rgeos") > library("RColorBrewer") > library("scales") > library("gridExtra") > > ##Shapefile from http://www.sharegeo.ac.uk/handle/10672/50 > > ##Working matched code > setwd("...") > gc<-read.csv("...dummy.csv", header=TRUE) > str(gc) > > ##'data.frame': 9 obs. of 3 variables: > ##$ NAME : Factor w/ 9 levels "East Midlands",..: 4 5 3 8 9 7 1 6 2 > ##$ Col_2: int 1 1 1 1 3 3 3 3 3 > ##$ Data : int 8 7 6 5 2 0 1 5 0 > > #Shape File and match file > frame<-readOGR(dsn=".../Regions", > layer="Regions") > str(frame) > plot(frame) > > frame@data=gc[match(frame@data[,"NAME"], gc[,"NAME"]),] > > ##Successfully merged, now to concatenate by territory > > ##Region 1 > #With internal boundaries > REGION1 <- frame[ which(frame$Col_2=='1'), ] > plot(REGION1) > #Joined so no internal boundaries > REGIONA <- gUnionCascaded(frame[ which(frame$Col_2=='1'), ]) > plot(REGIONA) > > ##Region 3 > #With internal boundaries > REGION3 <- frame[ which(frame$Col_2=='3'), ] > plot(REGION3) > #Joined so no internal boundaries > REGIONC <- gUnionCascaded(frame[ which(frame$Col_2=='3'), ]) > plot(REGIONC) > > > > -- > View this message in context: > http://r-sig-geo.2731867.n2.nabble.com/Choropleth-maps-using-matched-csv-shp-files-tp7586853.html > Sent from the R-sig-geo mailing list archive at Nabble.com. > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo