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@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")
<<attachment: Rplot01.png>>
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.