Skip to content

Commit 3c17320

Browse files
committed
fgitn
1 parent 65c5370 commit 3c17320

File tree

16 files changed

+75
-61
lines changed

16 files changed

+75
-61
lines changed

02_choropleth.Rmd

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ nc_pop <-
4141
#nc_pop
4242
```
4343

44-
```{}
45-
nc_pop <-
46-
get_acs(geography = "county",
47-
variables = "B01003_001",
48-
state = "NC",
49-
geometry = TRUE)
44+
```{r eval=FALSE, echo=TRUE}
45+
nc_pop <- get_acs(geography = "county",
46+
variables = "B01003_001",
47+
state = "NC",
48+
geometry = TRUE)
5049
```
5150

5251

038_facets_wrap_thematic_mapping.Rmd

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "Faceted Thematic Mapping"
33
---
44

55
```{r load-libraries, message=FALSE, warning=FALSE}
6-
library(tidyverse) # Tidyverse for Tidy Data
6+
library(tidyverse)
77
library(readxl)
88
library(tigris) # Get Census Geography Poloygons
99
library(sf)
@@ -15,15 +15,16 @@ library(tidycensus)
1515
Using the `tigris` package get Census Tiger shapefiles for census geographies. Tigris will return the shapefile in the `sf`, or simple features, format.
1616

1717
```{r get-data, message=FALSE, warning=FALSE}
18-
us_geo <- tigris::states(class = "sf") %>%
19-
shift_geometry()
18+
us_geo <- tigris::states(class = "sf", cb = TRUE) %>% #cb is a more generalized, less detailed file.
19+
shift_geometry() %>%
20+
filter(as.numeric(GEOID) < 60)
2021
```
2122

2223
## Get BLS data
2324

24-
I've already downloaded and stored some data from the Bureau of Labor Statistics. Thoses data are stored in an excel file in the `data` directory of the repository: `data/OES_Report.xlsx`. **The goal is to attach this data to the previously downloaded shapefiles.**
25+
I've already downloaded and stored some data from the Bureau of Labor Statistics. Those data are stored in an excel file in the `data` directory of the github repository: `data/OES_Report.xlsx`. **The goal is to attach this data to the previously downloaded shapefiles.**
2526

26-
But you may be intersted in how I gathered the data. below are some summary notes documenting my steps of gathering the data from the Bureau of Labor Statistics.
27+
But you may be interested in how I gathered the data. below are some summary notes documenting my steps of gathering the data from the Bureau of Labor Statistics.
2728

2829
https://data.bls.gov/oes/#/occGeo/One%20occupation%20for%20multiple%20geographical%20areas
2930

@@ -49,11 +50,9 @@ my_df <- my_xl_files %>%
4950
col_types = c("text", "numeric"),
5051
skip = 4,
5152
.id = "sheet")
52-
```
5353
54-
```{r}
5554
state_names <- us_geo %>%
56-
filter(REGION != "9") %>%
55+
# filter(REGION != "9") %>% jrljrl
5756
select(NAME) %>%
5857
st_drop_geometry()
5958
```
@@ -69,8 +68,7 @@ my_df <- my_df %>%
6968
wages = "Annual mean wage(2)",
7069
type = sheet) %>%
7170
mutate(State = str_extract(area, '.*(?=\\()')) %>%
72-
mutate(type = str_extract(type, "(?<=data/OES_)\\w+")) %>%
73-
filter(State != "Guam")
71+
mutate(type = str_extract(type, "(?<=data/OES_)\\w+"))
7472
```
7573

7674
### Missing data
@@ -106,16 +104,16 @@ my_df <- us_geo %>%
106104
Filter to the 50 states + D.C.
107105

108106
```{r}
109-
my_df <- my_df %>%
110-
filter(REGION != 9)
107+
my_df <- my_df # %>% jrljrl
108+
# filter(REGION != 9)
111109
```
112110

113111
## Get Population Data -- Tidycensus
114112

115113
### identify and pick census variables
116114

117-
B01003_001E = Total Population
118-
B06011_001E = Median income in the past 12 months
115+
- B01003_001E = Total Population
116+
- B06011_001E = Median income in the past 12 months
119117

120118
```{r identify_ACS_variables}
121119
variables_census <- load_variables(2015, "acs5", cache = TRUE)

039_facet_example.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title: "Example Faceted Thematic Mapping"
77
Beyond the the data wrangling, this faceted map was created using the `ggplot2::facet_wrap()` function.
88
See Also: [full data wrangling code](038_facets_wrap_thematic_mapping.html) and workflow.
99

10-
```{r eval=FALSE, include=FALSE, echo=TRUE}
10+
```{r eval=FALSE, echo=TRUE}
1111
sf_data %>%
1212
ggplot(aes(fill = wages, color = wages)) +
1313
geom_sf() +

docs/01_georeference.html

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

docs/02_choropleth.html

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

docs/038_facets_wrap_thematic_mapping.html

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,7 +2115,7 @@ <h1>Faceted Thematic Mapping</h1>
21152115
<div class="d-article">
21162116
<div class="layout-chunk" data-layout="l-body">
21172117
<div class="sourceCode">
2118-
<pre class="sourceCode r"><code class="sourceCode r"><span class='kw'><a href='https://rdrr.io/r/base/library.html'>library</a></span><span class='op'>(</span><span class='va'><a href='https://tidyverse.tidyverse.org'>tidyverse</a></span><span class='op'>)</span> <span class='co'># Tidyverse for Tidy Data</span>
2118+
<pre class="sourceCode r"><code class="sourceCode r"><span class='kw'><a href='https://rdrr.io/r/base/library.html'>library</a></span><span class='op'>(</span><span class='va'><a href='https://tidyverse.tidyverse.org'>tidyverse</a></span><span class='op'>)</span>
21192119
<span class='kw'><a href='https://rdrr.io/r/base/library.html'>library</a></span><span class='op'>(</span><span class='va'><a href='https://readxl.tidyverse.org'>readxl</a></span><span class='op'>)</span>
21202120
<span class='kw'><a href='https://rdrr.io/r/base/library.html'>library</a></span><span class='op'>(</span><span class='va'><a href='https://github.com/walkerke/tigris'>tigris</a></span><span class='op'>)</span> <span class='co'># Get Census Geography Poloygons</span>
21212121
<span class='kw'><a href='https://rdrr.io/r/base/library.html'>library</a></span><span class='op'>(</span><span class='va'><a href='https://r-spatial.github.io/sf/'>sf</a></span><span class='op'>)</span>
@@ -2127,14 +2127,15 @@ <h2 id="shapefiles-as-sf">Shapefiles as sf</h2>
21272127
<p>Using the <code>tigris</code> package get Census Tiger shapefiles for census geographies. Tigris will return the shapefile in the <code>sf</code>, or simple features, format.</p>
21282128
<div class="layout-chunk" data-layout="l-body">
21292129
<div class="sourceCode">
2130-
<pre class="sourceCode r"><code class="sourceCode r"><span class='va'>us_geo</span> <span class='op'>&lt;-</span> <span class='fu'>tigris</span><span class='fu'>::</span><span class='fu'><a href='https://rdrr.io/pkg/tigris/man/states.html'>states</a></span><span class='op'>(</span>class <span class='op'>=</span> <span class='st'>"sf"</span><span class='op'>)</span> <span class='op'>%&gt;%</span>
2131-
<span class='fu'><a href='https://rdrr.io/pkg/tigris/man/shift_geometry.html'>shift_geometry</a></span><span class='op'>(</span><span class='op'>)</span>
2130+
<pre class="sourceCode r"><code class="sourceCode r"><span class='va'>us_geo</span> <span class='op'>&lt;-</span> <span class='fu'>tigris</span><span class='fu'>::</span><span class='fu'><a href='https://rdrr.io/pkg/tigris/man/states.html'>states</a></span><span class='op'>(</span>class <span class='op'>=</span> <span class='st'>"sf"</span>, cb <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span> <span class='op'>%&gt;%</span> <span class='co'>#cb is a more generalized, less detailed file.</span>
2131+
<span class='fu'><a href='https://rdrr.io/pkg/tigris/man/shift_geometry.html'>shift_geometry</a></span><span class='op'>(</span><span class='op'>)</span> <span class='op'>%&gt;%</span>
2132+
<span class='fu'><a href='https://rdrr.io/r/stats/filter.html'>filter</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/numeric.html'>as.numeric</a></span><span class='op'>(</span><span class='va'>GEOID</span><span class='op'>)</span> <span class='op'>&lt;</span> <span class='fl'>60</span><span class='op'>)</span>
21322133
</code></pre>
21332134
</div>
21342135
</div>
21352136
<h2 id="get-bls-data">Get BLS data</h2>
2136-
<p>I’ve already downloaded and stored some data from the Bureau of Labor Statistics. Thoses data are stored in an excel file in the <code>data</code> directory of the repository: <code>data/OES_Report.xlsx</code>. <strong>The goal is to attach this data to the previously downloaded shapefiles.</strong></p>
2137-
<p>But you may be intersted in how I gathered the data. below are some summary notes documenting my steps of gathering the data from the Bureau of Labor Statistics.</p>
2137+
<p>I’ve already downloaded and stored some data from the Bureau of Labor Statistics. Those data are stored in an excel file in the <code>data</code> directory of the github repository: <code>data/OES_Report.xlsx</code>. <strong>The goal is to attach this data to the previously downloaded shapefiles.</strong></p>
2138+
<p>But you may be interested in how I gathered the data. below are some summary notes documenting my steps of gathering the data from the Bureau of Labor Statistics.</p>
21382139
<p><a href="https://data.bls.gov/oes/#/occGeo/One%20occupation%20for%20multiple%20geographical%20areas" class="uri">https://data.bls.gov/oes/#/occGeo/One%20occupation%20for%20multiple%20geographical%20areas</a></p>
21392140
<ul>
21402141
<li><p>One occupation for multiple geographical areas</p>
@@ -2160,13 +2161,9 @@ <h3 id="import-the-data-into-r">Import the Data into R</h3>
21602161
col_types <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='st'>"text"</span>, <span class='st'>"numeric"</span><span class='op'>)</span>,
21612162
skip <span class='op'>=</span> <span class='fl'>4</span>,
21622163
.id <span class='op'>=</span> <span class='st'>"sheet"</span><span class='op'>)</span>
2163-
</code></pre>
2164-
</div>
2165-
</div>
2166-
<div class="layout-chunk" data-layout="l-body">
2167-
<div class="sourceCode">
2168-
<pre class="sourceCode r"><code class="sourceCode r"><span class='va'>state_names</span> <span class='op'>&lt;-</span> <span class='va'>us_geo</span> <span class='op'>%&gt;%</span>
2169-
<span class='fu'><a href='https://rdrr.io/r/stats/filter.html'>filter</a></span><span class='op'>(</span><span class='va'>REGION</span> <span class='op'>!=</span> <span class='st'>"9"</span><span class='op'>)</span> <span class='op'>%&gt;%</span>
2164+
2165+
<span class='va'>state_names</span> <span class='op'>&lt;-</span> <span class='va'>us_geo</span> <span class='op'>%&gt;%</span>
2166+
<span class='co'># filter(REGION != "9") %&gt;% jrljrl</span>
21702167
<span class='fu'>select</span><span class='op'>(</span><span class='va'>NAME</span><span class='op'>)</span> <span class='op'>%&gt;%</span>
21712168
<span class='fu'><a href='https://r-spatial.github.io/sf/reference/st_geometry.html'>st_drop_geometry</a></span><span class='op'>(</span><span class='op'>)</span>
21722169
</code></pre>
@@ -2181,8 +2178,7 @@ <h3 id="wrangle-the-data">Wrangle the data</h3>
21812178
wages <span class='op'>=</span> <span class='st'>"Annual mean wage(2)"</span>,
21822179
type <span class='op'>=</span> <span class='va'>sheet</span><span class='op'>)</span> <span class='op'>%&gt;%</span>
21832180
<span class='fu'>mutate</span><span class='op'>(</span>State <span class='op'>=</span> <span class='fu'>str_extract</span><span class='op'>(</span><span class='va'>area</span>, <span class='st'>'.*(?=\\()'</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>%&gt;%</span>
2184-
<span class='fu'>mutate</span><span class='op'>(</span>type <span class='op'>=</span> <span class='fu'>str_extract</span><span class='op'>(</span><span class='va'>type</span>, <span class='st'>"(?&lt;=data/OES_)\\w+"</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>%&gt;%</span>
2185-
<span class='fu'><a href='https://rdrr.io/r/stats/filter.html'>filter</a></span><span class='op'>(</span><span class='va'>State</span> <span class='op'>!=</span> <span class='st'>"Guam"</span><span class='op'>)</span>
2181+
<span class='fu'>mutate</span><span class='op'>(</span>type <span class='op'>=</span> <span class='fu'>str_extract</span><span class='op'>(</span><span class='va'>type</span>, <span class='st'>"(?&lt;=data/OES_)\\w+"</span><span class='op'>)</span><span class='op'>)</span>
21862182
</code></pre>
21872183
</div>
21882184
</div>
@@ -2200,12 +2196,12 @@ <h3 id="missing-data">Missing data</h3>
22002196
</code></pre>
22012197
</div>
22022198
<pre><code> State type
2203-
1 North Carolina legislator
2204-
2 Vermont legislator
2205-
3 Kentucky legislator
2206-
4 Maine legislator
2207-
5 South Dakota legislator
2208-
6 District of Columbia legislator</code></pre>
2199+
1 Maine legislator
2200+
2 District of Columbia legislator
2201+
3 South Dakota legislator
2202+
4 Vermont legislator
2203+
5 Kentucky legislator
2204+
6 North Carolina legislator</code></pre>
22092205
</div>
22102206
<div class="layout-chunk" data-layout="l-body">
22112207
<div class="sourceCode">
@@ -2227,14 +2223,18 @@ <h3 id="states">50 states</h3>
22272223
<p>Filter to the 50 states + D.C.</p>
22282224
<div class="layout-chunk" data-layout="l-body">
22292225
<div class="sourceCode">
2230-
<pre class="sourceCode r"><code class="sourceCode r"><span class='va'>my_df</span> <span class='op'>&lt;-</span> <span class='va'>my_df</span> <span class='op'>%&gt;%</span>
2231-
<span class='fu'><a href='https://rdrr.io/r/stats/filter.html'>filter</a></span><span class='op'>(</span><span class='va'>REGION</span> <span class='op'>!=</span> <span class='fl'>9</span><span class='op'>)</span>
2226+
<pre class="sourceCode r"><code class="sourceCode r"><span class='va'>my_df</span> <span class='op'>&lt;-</span> <span class='va'>my_df</span> <span class='co'># %&gt;% jrljrl</span>
2227+
<span class='co'># filter(REGION != 9) </span>
22322228
</code></pre>
22332229
</div>
22342230
</div>
22352231
<h2 id="get-population-data-tidycensus">Get Population Data – Tidycensus</h2>
22362232
<h3 id="identify-and-pick-census-variables">identify and pick census variables</h3>
2237-
<p>B01003_001E = Total Population B06011_001E = Median income in the past 12 months</p>
2233+
<ul>
2234+
<li>B01003_001E = Total Population<br />
2235+
</li>
2236+
<li>B06011_001E = Median income in the past 12 months</li>
2237+
</ul>
22382238
<div class="layout-chunk" data-layout="l-body">
22392239
<div class="sourceCode">
22402240
<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>
@@ -2298,7 +2298,7 @@ <h3 id="display-map">Display Map</h3>
22982298
nrow <span class='op'>=</span> <span class='fl'>3</span>, ncol <span class='op'>=</span> <span class='fl'>2</span><span class='op'>)</span>
22992299
</code></pre>
23002300
</div>
2301-
<p><img src="038_facets_wrap_thematic_mapping_files/figure-html5/unnamed-chunk-10-1.png" width="624" /></p>
2301+
<p><img src="038_facets_wrap_thematic_mapping_files/figure-html5/unnamed-chunk-9-1.png" width="624" /></p>
23022302
</div>
23032303
<h3 id="save-map">Save Map</h3>
23042304
<div class="layout-chunk" data-layout="l-body">
Binary file not shown.
46.8 KB
Loading

docs/039_facet_example.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,6 +2116,19 @@ <h1>Example Faceted Thematic Mapping</h1>
21162116
<p><img src="facet_map.png" /></p>
21172117
<p>Beyond the the data wrangling, this faceted map was created using the <code>ggplot2::facet_wrap()</code> function.<br />
21182118
See Also: <a href="038_facets_wrap_thematic_mapping.html">full data wrangling code</a> and workflow.</p>
2119+
<div class="layout-chunk" data-layout="l-body">
2120+
<div class="sourceCode">
2121+
<pre class="sourceCode r"><code class="sourceCode r"><span class='va'>sf_data</span> <span class='op'>%&gt;%</span>
2122+
<span class='fu'>ggplot</span><span class='op'>(</span><span class='fu'>aes</span><span class='op'>(</span>fill <span class='op'>=</span> <span class='va'>wages</span>, color <span class='op'>=</span> <span class='va'>wages</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span>
2123+
<span class='fu'>geom_sf</span><span class='op'>(</span><span class='op'>)</span> <span class='op'>+</span>
2124+
<span class='fu'>coord_sf</span><span class='op'>(</span>crs <span class='op'>=</span> <span class='fl'>5070</span>, datum <span class='op'>=</span> <span class='cn'>NA</span><span class='op'>)</span> <span class='op'>+</span>
2125+
<span class='fu'>scale_fill_viridis_c</span><span class='op'>(</span><span class='op'>)</span> <span class='op'>+</span>
2126+
<span class='fu'>scale_color_viridis_c</span><span class='op'>(</span><span class='op'>)</span> <span class='op'>+</span>
2127+
<span class='fu'>facet_wrap</span><span class='op'>(</span><span class='op'>~</span> <span class='va'>category</span>,
2128+
nrow <span class='op'>=</span> <span class='fl'>3</span>, ncol <span class='op'>=</span> <span class='fl'>2</span><span class='op'>)</span>
2129+
</code></pre>
2130+
</div>
2131+
</div>
21192132
<div class="sourceCode" id="cb1"><pre class="sourceCode r distill-force-highlighting-css"><code class="sourceCode r"></code></pre></div>
21202133
<!--radix_placeholder_article_footer-->
21212134
<!--/radix_placeholder_article_footer-->

docs/facet_map.png

416 Bytes
Loading

0 commit comments

Comments
 (0)