Skip to content

Commit f545b10

Browse files
committed
ifg dananah
1 parent 8094fe5 commit f545b10

File tree

12 files changed

+156
-80
lines changed

12 files changed

+156
-80
lines changed

038_facets_wrap_thematic_mapping.Rmd

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ https://data.bls.gov/oes/#/occGeo/One%20occupation%20for%20multiple%20geographic
4040

4141
- Excel
4242

43-
### Import the Data into R
43+
### Import the data into R
4444

4545
```{r message=FALSE, warning=FALSE}
4646
my_xl_files <- fs::dir_ls(path = "data", glob = "*.xlsx")
@@ -98,9 +98,9 @@ my_df <- us_geo %>%
9898
left_join(my_df, by = c("NAME" = "State"))
9999
```
100100

101-
## Get Population Data -- Tidycensus
101+
## Get census data -- tidycensus
102102

103-
### identify and pick census variables
103+
### Identify and pick census variables
104104

105105
If you're not sure what 2015 ACS Census data variables you need, you'll want to investigate the variables.
106106

@@ -113,9 +113,11 @@ I'm using Median income.
113113
- B01003_001E = Total Population
114114
- B06011_001E = Median income in the past 12 months
115115

116-
### Get Median Income
116+
_Note: I realize mean and median are not the same measure. This is a demonstration of procedure, not a recommendation for research practice and data comparison. Of course, you will be more rigorous with your own research._
117117

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).
118+
### Get BLS mean income
119+
120+
Now that I know the Census ACS variable, I can use the `tidycensus::get_acs()` function to gather the mean income variable for each state, along with the geometry (i.e. shapefiles).
119121

120122
```{r get_median_income}
121123
us_pop <-
@@ -129,15 +131,15 @@ us_pop <- us_pop %>%
129131
rename(wages = estimate)
130132
```
131133

132-
### Append Census Data
134+
### Append Census data
133135

134136
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()`
135137

136138
```{r}
137139
my_df <- bind_rows(my_df, us_pop)
138140
```
139141

140-
### More Munging
142+
### More munging
141143

142144
Make the category variable a categorical factor with levels. This will improve the order of the facets when displayed.
143145

@@ -158,7 +160,7 @@ my_df <- my_df %>%
158160
mutate(category = factor(category, display_levels))
159161
```
160162

161-
### Display Map
163+
### Display map
162164

163165
```{r makethemap, fig.height=9, fig.width=8, dev='svg'}
164166
my_df %>%
@@ -170,13 +172,13 @@ my_df %>%
170172
facet_wrap(~ category,
171173
nrow = 3, ncol = 2) +
172174
theme(legend.position = "top") +
173-
labs(title = "2015 Median USA Wages by Professions",
174-
subtitle = "A comparison",
175+
labs(title = "2015 Mean USA Wages by Professions",
176+
subtitle = "A comparison of BLS mean income with Census median income",
175177
color = "", fill = "",
176178
caption = "Source: BLS & Census")
177179
```
178180

179-
### Save Map
181+
### Save map
180182

181183
```{r save_it}
182184
ggsave("facet_map.svg", width = 8, height = 9, units = "in")

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 & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,7 +2151,7 @@ <h2 id="get-bls-data">Get BLS data</h2>
21512151
</ul></li>
21522152
</ul></li>
21532153
</ul>
2154-
<h3 id="import-the-data-into-r">Import the Data into R</h3>
2154+
<h3 id="import-the-data-into-r">Import the data into R</h3>
21552155
<div class="layout-chunk" data-layout="l-body">
21562156
<div class="sourceCode">
21572157
<pre class="sourceCode r"><code class="sourceCode r"><span class='va'>my_xl_files</span> <span class='op'>&lt;-</span> <span class='fu'>fs</span><span class='fu'>::</span><span class='fu'><a href='http://fs.r-lib.org/reference/dir_ls.html'>dir_ls</a></span><span class='op'>(</span>path <span class='op'>=</span> <span class='st'>"data"</span>, glob <span class='op'>=</span> <span class='st'>"*.xlsx"</span><span class='op'>)</span>
@@ -2218,8 +2218,8 @@ <h3 id="join-data">Join data</h3>
22182218
</code></pre>
22192219
</div>
22202220
</div>
2221-
<h2 id="get-population-data-tidycensus">Get Population DataTidycensus</h2>
2222-
<h3 id="identify-and-pick-census-variables">identify and pick census variables</h3>
2221+
<h2 id="get-census-data-tidycensus">Get census datatidycensus</h2>
2222+
<h3 id="identify-and-pick-census-variables">Identify and pick census variables</h3>
22232223
<p>If you’re not sure what 2015 ACS Census data variables you need, you’ll want to investigate the variables.</p>
22242224
<div class="layout-chunk" data-layout="l-body">
22252225
<div class="sourceCode">
@@ -2233,8 +2233,9 @@ <h3 id="identify-and-pick-census-variables">identify and pick census variables</
22332233
</li>
22342234
<li>B06011_001E = Median income in the past 12 months</li>
22352235
</ul>
2236-
<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>
2236+
<p><em>Note: I realize mean and median are not the same measure. This is a demonstration of procedure, not a recommendation for research practice and data comparison. Of course, you will be more rigorous with your own research.</em></p>
2237+
<h3 id="get-bls-mean-income">Get BLS mean income</h3>
2238+
<p>Now that I know the Census ACS variable, I can use the <code>tidycensus::get_acs()</code> function to gather the mean income variable for each state, along with the geometry (i.e. shapefiles).</p>
22382239
<div class="layout-chunk" data-layout="l-body">
22392240
<div class="sourceCode">
22402241
<pre class="sourceCode r"><code class="sourceCode r"><span class='va'>us_pop</span> <span class='op'>&lt;-</span>
@@ -2249,15 +2250,15 @@ <h3 id="get-median-income">Get Median Income</h3>
22492250
</code></pre>
22502251
</div>
22512252
</div>
2252-
<h3 id="append-census-data">Append Census Data</h3>
2253+
<h3 id="append-census-data">Append Census data</h3>
22532254
<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>
22542255
<div class="layout-chunk" data-layout="l-body">
22552256
<div class="sourceCode">
22562257
<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>
22572258
</code></pre>
22582259
</div>
22592260
</div>
2260-
<h3 id="more-munging">More Munging</h3>
2261+
<h3 id="more-munging">More munging</h3>
22612262
<p>Make the category variable a categorical factor with levels. This will improve the order of the facets when displayed.</p>
22622263
<div class="layout-chunk" data-layout="l-body">
22632264
<div class="sourceCode">
@@ -2278,7 +2279,7 @@ <h3 id="more-munging">More Munging</h3>
22782279
</code></pre>
22792280
</div>
22802281
</div>
2281-
<h3 id="display-map">Display Map</h3>
2282+
<h3 id="display-map">Display map</h3>
22822283
<div class="layout-chunk" data-layout="l-body">
22832284
<div class="sourceCode">
22842285
<pre class="sourceCode r"><code class="sourceCode r"><span class='va'>my_df</span> <span class='op'>%&gt;%</span>
@@ -2290,15 +2291,15 @@ <h3 id="display-map">Display Map</h3>
22902291
<span class='fu'>facet_wrap</span><span class='op'>(</span><span class='op'>~</span> <span class='va'>category</span>,
22912292
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>
22922293
<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>
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>,
2294-
subtitle <span class='op'>=</span> <span class='st'>"A comparison"</span>,
2294+
<span class='fu'>labs</span><span class='op'>(</span>title <span class='op'>=</span> <span class='st'>"2015 Mean USA Wages by Professions"</span>,
2295+
subtitle <span class='op'>=</span> <span class='st'>"A comparison of BLS mean income with Census median income"</span>,
22952296
color <span class='op'>=</span> <span class='st'>""</span>, fill <span class='op'>=</span> <span class='st'>""</span>,
22962297
caption <span class='op'>=</span> <span class='st'>"Source: BLS &amp; Census"</span><span class='op'>)</span>
22972298
</code></pre>
22982299
</div>
22992300
<p><img src="038_facets_wrap_thematic_mapping_files/figure-html5/makethemap-1.svg" width="768" /></p>
23002301
</div>
2301-
<h3 id="save-map">Save Map</h3>
2302+
<h3 id="save-map">Save map</h3>
23022303
<div class="layout-chunk" data-layout="l-body">
23032304
<div class="sourceCode">
23042305
<pre class="sourceCode r"><code class="sourceCode r"><span class='fu'>ggsave</span><span class='op'>(</span><span class='st'>"facet_map.svg"</span>, width <span class='op'>=</span> <span class='fl'>8</span>, height <span class='op'>=</span> <span class='fl'>9</span>, units <span class='op'>=</span> <span class='st'>"in"</span><span class='op'>)</span>

0 commit comments

Comments
 (0)