diff --git a/.gitignore b/.gitignore index 96374c4..a992975 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ $RECYCLE.BIN/ Network Trash Folder Temporary Items .apdisk +.Rproj.user diff --git a/IntroToMapping.Rmd b/IntroToMapping.Rmd index e43dd71..e8a43ab 100644 --- a/IntroToMapping.Rmd +++ b/IntroToMapping.Rmd @@ -79,19 +79,35 @@ data("df_zip_demographics") kable(head(df_zip_demographics)) ``` -## Population: Washington - -```{r} -dfzipmedrent=df_zip_demographics[,c(1,8)] -colnames(dfzipmedrent)=c("region","value") -zip_choropleth(dfzipmedrent,state_zoom="washington")+coord_map() #adds mercator projection +## Population Density Choropleths +Use population density (population per area) rather than raw count for a sound spatial analysis. A good explanation of the trouble with choropleth maps of raw count data is available in Monmonier, Mark, _Mapping It Out: Expository Cartography for the Humanities and Social Sciences_ (1993: University of Chicago Press, Chicago). Pages 159-167. + +```{r pop density intro} +library(dplyr) +data(zip.map) #Pull ZCTA area from `choroplethrZip` package data sets to compute density +zarea <- zip.map %>% group_by(region) %>% + summarize(zland = first(ALAND10), zwater = first(AWATER10)) +df_pop_zip <- df_pop_zip %>% merge(zarea, all.x = TRUE) +df_pop_zip$popdensity <- with(df_pop_zip, count / (zland + zwater) * 1000 ^ 2) +kable(head(df_pop_zip)) ``` -## Population: Spokane County (FIPS 53063) -```{r} +## Population Density: Washington + +Use an equal area projection since the measure is normalized by area. + +```{r wash state pop density} +df_pop_zip$value <- df_pop_zip$popdensity +zip_choropleth(df_pop_zip, state_zoom = 'washington', legend = 'Count per km^2') + + coord_map(projection = 'albers', lat0 = 41, lat1 = 47) # equal area projection for pacific NW http://spatialreference.org/ref/sr-org/nad83-us-pacific-northwest-albers/html/ +``` + +## Population Density: Spokane County (FIPS 53063) -zip_choropleth(dfzipmedrent, county_zoom=53063) + coord_map() +```{r county zcta pop density} +zip_choropleth(df_pop_zip, county_zoom = 53063, legend = 'Count per km^2') + + coord_map(projection = 'albers', lat0 = 41, lat1 = 47) ``` ## Interactive map using leaflet, tigris and acs diff --git a/IntroToMapping.html b/IntroToMapping.html index dc373bd..62825ca 100644 --- a/IntroToMapping.html +++ b/IntroToMapping.html @@ -86,7 +86,7 @@ - + @@ -411,24 +411,98 @@
-dfzipmedrent=df_zip_demographics[,c(1,8)]
-colnames(dfzipmedrent)=c("region","value")
-zip_choropleth(dfzipmedrent,state_zoom="washington")+coord_map() #adds mercator projection
+Use population density (population per area) rather than raw count for a sound spatial analysis. A good explanation of the trouble with choropleth maps of raw count data is available in Monmonier, Mark, Mapping It Out: Expository Cartography for the Humanities and Social Sciences (1993: University of Chicago Press, Chicago). Pages 159-167.
-library(dplyr) +data(zip.map) #Pull ZCTA area from `choroplethrZip` package data sets to compute density +zarea <- zip.map %>% group_by(region) %>% + summarize(zland = first(ALAND10), zwater = first(AWATER10)) +df_pop_zip <- df_pop_zip %>% merge(zarea, all.x = TRUE) +df_pop_zip$popdensity <- with(df_pop_zip, count / (zland + zwater) * 1000 ^ 2) +kable(head(df_pop_zip))-
| region | +zland | +zwater | +value | +count | +popdensity | +
|---|---|---|---|---|---|
| 01001 | +29635482 | +2229764 | +545.421805 | +17380 | +545.421805 | +
| 01002 | +142559990 | +4276576 | +195.577987 | +28718 | +195.577987 | +
| 01003 | +1842385 | +12788 | +6083.529676 | +11286 | +6083.529676 | +
| 01005 | +114586901 | +667043 | +44.423642 | +5120 | +44.423642 | +
| 01007 | +136346000 | +6943850 | +101.842524 | +14593 | +101.842524 | +
| 01008 | +139331464 | +5086093 | +8.032264 | +1160 | +8.032264 | +
Use an equal area projection since the measure is normalized by area.
+ +df_pop_zip$value <- df_pop_zip$popdensity +zip_choropleth(df_pop_zip, state_zoom = 'washington', legend = 'Count per km^2') + + coord_map(projection = 'albers', lat0 = 41, lat1 = 47) # equal area projection for pacific NW http://spatialreference.org/ref/sr-org/nad83-us-pacific-northwest-albers/html/+ +
zip_choropleth(dfzipmedrent, county_zoom=53063) + coord_map()+
zip_choropleth(df_pop_zip, county_zoom = 53063, legend = 'Count per km^2') + + coord_map(projection = 'albers', lat0 = 41, lat1 = 47)-
| Address | -latitude | -longitude | +latitude | +longitude |
|---|---|---|---|---|
| 502 E Boone Ave, Spokane, WA, 99258 | -47.6683 | --117.403 | +NA | +NA |
| 502 E Boone Ave, Spokane, WA, 99258 | -47.6683 | --117.403 | +NA | +NA |
leaflet packagelibrary(leaflet) #rstudio package leaflet() %>% addTiles()- - + +
leaflet() %>% addTiles()%>%addCircleMarkers(data=thingstodo)- - + +
leaflet() %>% addTiles()%>%addCircleMarkers(data=thingstodo,popup=~Attraction,radius=~Population*.05)- - + +
leaflet() %>% addTiles()%>%addMarkers(data=thingstodo,popup=~Attraction)- - + +
leaflet() %>% addTiles()%>%addMarkers(data=thingstodo,popup=~Attraction)%>% addPolylines(thingstodo$lon,thingstodo$lat)- - + +