Hi,

I have a dataframe listing US counties and a number per county and I have a
shapefile of the US with county ID's. I would like to plot the "number"
variable on a map (in the shapefile) using a color range per county (e.g.
white = min(number) = 2, black = max(number) = 15). Can anyone help me
actually plotting the data on the map? This is how far I got. Thanks!

DF = data.frame(read.table(textConnection(" A CNTY_FIPS number
1 US001 2
2 US002 8
3 US003 3
4 US004 5
5 US005 6
6 US006 7
7 US007 9
8 US008 9
9 US009 10
10 US010 11
11 US011 13
12 US012 15"),head=TRUE,stringsAsFactors=FALSE))

library(maptools)
library(ggplot2)
library(gpclib)
gpclibPermit()
setwd("C:/Documents")
us_counties.shp <- readShapeSpatial("uscounties.shp")
us_counties.shp.p <- fortify.SpatialPolygonsDataFrame(us_counties.shp,
region="CNTY_FIPS")
us <- merge(us_counties.shp.p, us_counties.shp, by.x="id", by.y="CNTY_FIPS")
p <- ggplot(data=us, aes(x=long, y=lat, group=group)) +
geom_polygon(fill="#CFCFCF")
p <- p + geom_path(color="white") + coord_equal()
ggsave(p, width=11.69, height=8.27, file="us_counties_a.jpg")

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to