[R] adding legend to choropleth map using GISTools
Martha Zorn
mzorn at schoolph.umass.edu
Mon Jan 13 00:19:30 CET 2014
I am having problems with adding legend to choropleth map using GISTools. The map that I get does not include a legend (see attached). Thanks for any help you can provide.
Below is my code:
#read in sample
at001<-read.csv("C:/Users/martha/Dropbox/shiny/sample.csv")
a <- matrix(at001$npovr, ncol=1)
rownames(a) <- as.character(at001$County)
##Sets working libraries for following code
library(GISTools)
library(classInt)
##Reads in MA County shape file
#at work MAcounties<-readShapeSpatial("J:/Projects/Gambling/web/shiny/co25_d00_shp/co25_d00.shp")
MAcounties<-readShapeSpatial("C:/Users/martha/Dropbox/shiny/co25_d00_shp/co25_d00.shp")
sorted.a <- a[MAcounties at data[,"NAME"], 1]
shades <- auto.shading(sorted.a, n = 6, cutter = rangeCuts, cols = brewer.pal(6, "Greens"))
# Draw a map based on this scheme
choropleth(MAcounties,sorted.a,shades)
# Add a legend based on this scheme
choro.legend(-82, 34.87, shades, fmt = "%4.1f", title = "Poverty Rates")
# Add a title to the map
title("Poverty Rates in Massachusetts by County")
# ... and a little more explanatory text
text(-85.3, 30.4, "Source: XXXXXX")
# and draw a box around it
box(which = "outer")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Rplot01.png
Type: image/png
Size: 5072 bytes
Desc: Rplot01.png
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20140112/39ab58da/attachment.png>
More information about the R-help
mailing list