r - Drawing choropleth map - 'Aesthetics error' in ggmap -


everyone!

i attempting create choropleth map of denver metro area, showing different housing values census tract. when try map, gives me 'error: aesthetics must either length 1 or same data (83658): x, y, group, fill'... how solve problem, can create visual map?

i read through various questions none appeared answer problem. suggestions appreciated. sample of 20 (of 588) data points below.

thanks!

1.load packages

library(maptools) library(ggmap) library(ggthemes) library(rgdal) 

2.select, define, plot initial map

 denvermetro <- c(-105, 40, -104.8535, 39.3760)     denvermetromap <- get_map(location=denvermetro,                                source = "google",                                maptype = "roadmap",                               zoom = 10,                               crop=false)     ggmap(denvermetromap) 

3.import polygons shp file

denvermetrocensustracts <-readogr(dsn = "c://users/john/denver_housing_project/acs_data/final_data", layer = "cb_2013_08_tract_500k") proj4string(denvermetrocensustracts) denvermetrocensustracts <-sptransform(denvermetrocensustracts,                               crs("+proj=longlat + datum=wgs84")) 

4.create initial census tract map

ggmap(denvermetromap) + geom_polygon(aes(x = long, y = lat, group=id),              data = denvermetrocensustracts,               color="white",               fill="orange",              alpha = .4, size = .2) 

5a.import denver housing data, make 1 variable numeric, , merge census shapefile

        setwd('c:/users/john/denver_housing_project/acs_data/final_data')         median_values_acs_13_dhp <-read.csv('acs_13_5yr_b25077_dhp.csv',          na.strings=c("na", "-", "?", "(x)"), header=true)         names(median_values_acs_13_dhp) <-c("affgeoid", "id2", "geography", "year",                                              "housevalue_median", "housevalue_median_moe_dhp")   housevalue_median=as.numeric(as.character(median_values_acs_13_dhp$housevalue_median))  mapping  <-merge(denvermetrocensustracts, median_values_acs_13_dhp, by.x="affgeoid")  

6.create choropleth map

ggmap(denvermetromap) + geom_polygon(aes(x = long, y = lat, group = id,   fill = housevalue_median), data = mapping, alpha = .4, size = .2) +  scale_fill_gradient() 

geo.id geo.id2 geo.display-label year hd01_vd01 hd02_vd01 1400000us08001007801 8001007801 census tract 78.01, adams county, colorado 2013 150300 40311 1400000us08001007802 8001007802 census tract 78.02, adams county, colorado 2013 114700 4570 1400000us08001007900 8001007900 census tract 79, adams county, colorado 2013 118600 8228 1400000us08001008000 8001008000 census tract 80, adams county, colorado 2013 139000 10440 1400000us08001008100 8001008100 census tract 81, adams county, colorado 2013 29800 105549 1400000us08001008200 8001008200 census tract 82, adams county, colorado 2013 145100 6189 1400000us08001008308 8001008308 census tract 83.08, adams county, colorado 2013 46300 67342 1400000us08001988700 8001988700 census tract 9887, adams county, colorado 2013 - ** 1400000us08001008309 8001008309 census tract 83.09, adams county, colorado 2013 36600 18824 1400000us08001008353 8001008353 census tract 83.53, adams county, colorado 2013 134600 8921 1400000us08001008401 8001008401 census tract 84.01, adams county, colorado 2013 241300 43038 1400000us08001008402 8001008402 census tract 84.02, adams county, colorado 2013 215900 15189 1400000us08001008505 8001008505 census tract 85.05, adams county, colorado 2013 174100 6525 1400000us08001008506 8001008506 census tract 85.06, adams county, colorado 2013 157300 15556 1400000us08001008507 8001008507 census tract 85.07, adams county, colorado 2013 177800 5644 1400000us08001008508 8001008508 census tract 85.08, adams county, colorado 2013 188700 10424 1400000us08001008523 8001008523 census tract 85.23, adams county, colorado 2013 268500 29657 1400000us08001008524 8001008524 census tract 85.24, adams county, colorado 2013 231200 4994 1400000us08001008526 8001008526 census tract 85.26, adams county, colorado 2013 284900 14945


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -