From 0f22b6a2235fcb17886f939006b36d179f65068d Mon Sep 17 00:00:00 2001 From: Jason Brown Date: Wed, 26 Aug 2015 13:14:33 -0400 Subject: [PATCH 1/3] Present population density choropleths instead of count-based choropleth. --- IntroToMapping.Rmd | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) 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 From 129cbe5d4ba73dbc8766b572099016a2c00e4ff8 Mon Sep 17 00:00:00 2001 From: Jason Brown Date: Wed, 26 Aug 2015 13:22:04 -0400 Subject: [PATCH 2/3] Population density choropleths instead of count choropleths. --- IntroToMapping.Rmd | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) 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 From a1ba7692d95b5a0caef0f710bf4da32b9291b299 Mon Sep 17 00:00:00 2001 From: Jason Brown Date: Wed, 2 Sep 2015 09:49:44 -0400 Subject: [PATCH 3/3] Add .html for pop density edits. --- .gitignore | 1 + IntroToMapping.html | 140 +++++++++++++++++++++++++++++++++----------- 2 files changed, 108 insertions(+), 33 deletions(-) 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.html b/IntroToMapping.html index dc373bd..62825ca 100644 --- a/IntroToMapping.html +++ b/IntroToMapping.html @@ -86,7 +86,7 @@ - + @@ -411,24 +411,98 @@

-

Population: Washington

+

Population Density Choropleths

-
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))
-

Population: Spokane County (FIPS 53063)

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
regionzlandzwatervaluecountpopdensity
01001296354822229764545.42180517380545.421805
010021425599904276576195.57798728718195.577987
010031842385127886083.529676112866083.529676
0100511458690166704344.423642512044.423642
010071363460006943850101.84252414593101.842524
0100813933146450860938.03226411608.032264
+ +

Population Density: Washington

+ +

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/
+ +

+ +

Population Density: Spokane County (FIPS 53063)

-
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)
-

+

Interactive map using leaflet, tigris and acs

-

-

+

+

Points

@@ -461,18 +535,18 @@

- - + + - - + + - - + +
Addresslatitudelongitudelatitudelongitude
502 E Boone Ave, Spokane, WA, 9925847.6683-117.403NANA
502 E Boone Ave, Spokane, WA, 9925847.6683-117.403NANA
@@ -483,7 +557,7 @@

spokanemap=ggmap(map) print(spokanemap) -

+

Add Attractions

@@ -491,7 +565,7 @@

aes(lon,lat,color=Attraction),size=5) print(spokanemap) -

+

Some Cleaning

@@ -500,7 +574,7 @@

axis.text = element_blank(),axis.title = element_blank(), axis.ticks = element_blank()) -

+

A traveling student's route

@@ -511,7 +585,7 @@

ggmap(newmap,darken=.3)+geom_text(data=thingstodo,aes(lon,lat,label=Attraction), color="white",size=3) -

+

R-Studio's leaflet package

@@ -522,42 +596,42 @@

library(leaflet) #rstudio package
 leaflet() %>% addTiles()
-

-

+

+

Add our points of attraction

leaflet() %>% addTiles()%>%addCircleMarkers(data=thingstodo)
-

-

+

+

Give more information

leaflet() %>% addTiles()%>%addCircleMarkers(data=thingstodo,popup=~Attraction,radius=~Population*.05)
-

-

+

+

Markers

leaflet() %>% addTiles()%>%addMarkers(data=thingstodo,popup=~Attraction)
-

-

+

+

Routes

leaflet() %>% addTiles()%>%addMarkers(data=thingstodo,popup=~Attraction)%>% 
   addPolylines(thingstodo$lon,thingstodo$lat)
-

-

+

+

Few Controls

-

-

+

+

Leaflet+Shiny+DataTable