Skip to content

Commit 8094fe5

Browse files
committed
gefn
1 parent e8dcdd6 commit 8094fe5

File tree

12 files changed

+144
-75
lines changed

12 files changed

+144
-75
lines changed

038_facets_wrap_thematic_mapping.Rmd

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ my_df <- my_df %>%
9191

9292
### Join data
9393

94-
Using the `dplyr::left_join` merge BLS data to the previously loaded shape object
94+
Using the `dplyr::left_join`, merge BLS data with the `us_geo` geometry, i.e. the shapefile object
9595

9696
```{r}
9797
my_df <- us_geo %>%
@@ -102,15 +102,21 @@ my_df <- us_geo %>%
102102

103103
### identify and pick census variables
104104

105-
- B01003_001E = Total Population
106-
- B06011_001E = Median income in the past 12 months
105+
If you're not sure what 2015 ACS Census data variables you need, you'll want to investigate the variables.
107106

108107
```{r identify_ACS_variables}
109108
variables_census <- load_variables(2015, "acs5", cache = TRUE)
110109
```
111110

111+
I'm using Median income.
112+
113+
- B01003_001E = Total Population
114+
- B06011_001E = Median income in the past 12 months
115+
112116
### Get Median Income
113117

118+
Now that I know the Census ACS variable, I can use the `tidycensus::get_acs()` function to gather the median income variable for each state, along with the geometry (i.e. shapefiles).
119+
114120
```{r get_median_income}
115121
us_pop <-
116122
get_acs(geography = "state",
@@ -120,12 +126,13 @@ us_pop <-
120126
121127
us_pop <- us_pop %>%
122128
mutate(type = "USA Median Income") %>%
123-
rename(wages = estimate) %>%
124-
filter(NAME != "Puerto Rico")
129+
rename(wages = estimate)
125130
```
126131

127132
### Append Census Data
128133

134+
Now combine the tidycensus data and geometry (i.e. `us_pop` variable data & shapefiles) with the BLS data and previously associate shapefiles gatheried via `tigris::states()`
135+
129136
```{r}
130137
my_df <- bind_rows(my_df, us_pop)
131138
```
@@ -163,7 +170,7 @@ my_df %>%
163170
facet_wrap(~ category,
164171
nrow = 3, ncol = 2) +
165172
theme(legend.position = "top") +
166-
labs(title = "Median USA Wages by Professions",
173+
labs(title = "2015 Median USA Wages by Professions",
167174
subtitle = "A comparison",
168175
color = "", fill = "",
169176
caption = "Source: BLS & Census")

docs/01_georeference.html

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

docs/02_choropleth.html

Lines changed: 6 additions & 6 deletions
Large diffs are not rendered by default.

docs/038_facets_wrap_thematic_mapping.html

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,7 @@ <h3 id="missing-data">Missing data</h3>
22102210
</div>
22112211
</div>
22122212
<h3 id="join-data">Join data</h3>
2213-
<p>Using the <code>dplyr::left_join</code> merge BLS data to the previously loaded shape object</p>
2213+
<p>Using the <code>dplyr::left_join</code>, merge BLS data with the <code>us_geo</code> geometry, i.e. the shapefile object</p>
22142214
<div class="layout-chunk" data-layout="l-body">
22152215
<div class="sourceCode">
22162216
<pre class="sourceCode r"><code class="sourceCode r"><span class='va'>my_df</span> <span class='op'>&lt;-</span> <span class='va'>us_geo</span> <span class='op'>%&gt;%</span>
@@ -2220,18 +2220,21 @@ <h3 id="join-data">Join data</h3>
22202220
</div>
22212221
<h2 id="get-population-data-tidycensus">Get Population Data – Tidycensus</h2>
22222222
<h3 id="identify-and-pick-census-variables">identify and pick census variables</h3>
2223-
<ul>
2224-
<li>B01003_001E = Total Population<br />
2225-
</li>
2226-
<li>B06011_001E = Median income in the past 12 months</li>
2227-
</ul>
2223+
<p>If you’re not sure what 2015 ACS Census data variables you need, you’ll want to investigate the variables.</p>
22282224
<div class="layout-chunk" data-layout="l-body">
22292225
<div class="sourceCode">
22302226
<pre class="sourceCode r"><code class="sourceCode r"><span class='va'>variables_census</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/tidycensus/man/load_variables.html'>load_variables</a></span><span class='op'>(</span><span class='fl'>2015</span>, <span class='st'>"acs5"</span>, cache <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span>
22312227
</code></pre>
22322228
</div>
22332229
</div>
2230+
<p>I’m using Median income.</p>
2231+
<ul>
2232+
<li>B01003_001E = Total Population<br />
2233+
</li>
2234+
<li>B06011_001E = Median income in the past 12 months</li>
2235+
</ul>
22342236
<h3 id="get-median-income">Get Median Income</h3>
2237+
<p>Now that I know the Census ACS variable, I can use the <code>tidycensus::get_acs()</code> function to gather the median income variable for each state, along with the geometry (i.e. shapefiles).</p>
22352238
<div class="layout-chunk" data-layout="l-body">
22362239
<div class="sourceCode">
22372240
<pre class="sourceCode r"><code class="sourceCode r"><span class='va'>us_pop</span> <span class='op'>&lt;-</span>
@@ -2242,12 +2245,12 @@ <h3 id="get-median-income">Get Median Income</h3>
22422245

22432246
<span class='va'>us_pop</span> <span class='op'>&lt;-</span> <span class='va'>us_pop</span> <span class='op'>%&gt;%</span>
22442247
<span class='fu'>mutate</span><span class='op'>(</span>type <span class='op'>=</span> <span class='st'>"USA Median Income"</span><span class='op'>)</span> <span class='op'>%&gt;%</span>
2245-
<span class='fu'>rename</span><span class='op'>(</span>wages <span class='op'>=</span> <span class='va'>estimate</span><span class='op'>)</span> <span class='op'>%&gt;%</span>
2246-
<span class='fu'><a href='https://rdrr.io/r/stats/filter.html'>filter</a></span><span class='op'>(</span><span class='va'>NAME</span> <span class='op'>!=</span> <span class='st'>"Puerto Rico"</span><span class='op'>)</span>
2248+
<span class='fu'>rename</span><span class='op'>(</span>wages <span class='op'>=</span> <span class='va'>estimate</span><span class='op'>)</span>
22472249
</code></pre>
22482250
</div>
22492251
</div>
22502252
<h3 id="append-census-data">Append Census Data</h3>
2253+
<p>Now combine the tidycensus data and geometry (i.e. <code>us_pop</code> variable data &amp; shapefiles) with the BLS data and previously associate shapefiles gatheried via <code>tigris::states()</code></p>
22512254
<div class="layout-chunk" data-layout="l-body">
22522255
<div class="sourceCode">
22532256
<pre class="sourceCode r"><code class="sourceCode r"><span class='va'>my_df</span> <span class='op'>&lt;-</span> <span class='fu'>bind_rows</span><span class='op'>(</span><span class='va'>my_df</span>, <span class='va'>us_pop</span><span class='op'>)</span>
@@ -2287,7 +2290,7 @@ <h3 id="display-map">Display Map</h3>
22872290
<span class='fu'>facet_wrap</span><span class='op'>(</span><span class='op'>~</span> <span class='va'>category</span>,
22882291
nrow <span class='op'>=</span> <span class='fl'>3</span>, ncol <span class='op'>=</span> <span class='fl'>2</span><span class='op'>)</span> <span class='op'>+</span>
22892292
<span class='fu'>theme</span><span class='op'>(</span>legend.position <span class='op'>=</span> <span class='st'>"top"</span><span class='op'>)</span> <span class='op'>+</span>
2290-
<span class='fu'>labs</span><span class='op'>(</span>title <span class='op'>=</span> <span class='st'>"Median USA Wages by Professions"</span>,
2293+
<span class='fu'>labs</span><span class='op'>(</span>title <span class='op'>=</span> <span class='st'>"2015 Median USA Wages by Professions"</span>,
22912294
subtitle <span class='op'>=</span> <span class='st'>"A comparison"</span>,
22922295
color <span class='op'>=</span> <span class='st'>""</span>, fill <span class='op'>=</span> <span class='st'>""</span>,
22932296
caption <span class='op'>=</span> <span class='st'>"Source: BLS &amp; Census"</span><span class='op'>)</span>

0 commit comments

Comments
 (0)