Helen Jenkins
2011-Jan-13 17:31 UTC
[R] Colouring areas on a map with updated maptools functions
Hi - I'm trying to plot a map from a shapefile and then colour different areas of it depending on different attributes of those areas. A couple of years ago I used some code to do this that would plot a map in R from a shapefile (states within a country). It then uploaded a .txt file which had the same number of rows as the shapefile and one column populated with numbers from 1 to 8 which represented an attribute for each of those states. The code then plotted those numbers as colours on the map so each state had the appropriate colour. This was the code: x<-read.shape("NGADMIN2.SHP") xpolys<-Map2poly(x) coverage<-read.table("coveragemar08.txt",header=T) colour1<-coverage[,2] palette(c("red4","red3","red2","orangered","orange","gold1","yellow","white")) plot(xpolys, axes=F, colour1) I've now come back to using this and discovered that some of these functions are no longer in use. I've figured out how to change most of it and now have this: x=readShapePoly("NGADMIN2.shp") coverage<-read.table("coveragemar08.txt",header=T) colour1<-coverage[,2] palette(c("red4","red3","red2","orangered","orange","gold1","yellow","white")) plot(x, axes=F, colour1) but it falls over at the last line. It doesn't like the inclusion of ",colour1" and I get an error: Error in as.double(x) : cannot coerce type 'S4' to vector of type 'double' I cannot work out how to fix this. Can anyone help? Or do I need to change something else about how I'm doing this? Thanks in advance Helen [[alternative HTML version deleted]]