You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 01_georeference.Rmd
+3-13Lines changed: 3 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,14 @@
1
1
---
2
2
title: Latitude and Longitude Coordinates
3
-
output: html_document
4
-
# html_document:
5
-
# toc: FALSE
6
3
---
7
-
8
-
9
-
To introduce the [`mapview` package](https://r-spatial.github.io/mapview/index.html), make an interactive map with Starbucks coffee shop locations in North Carolina (2012). (Adapted from Machlis.)^[[5 Visualizations in 5 Minutes](http://www.computerworld.com/article/2893271/business-intelligence/5-data-visualizations-in-5-minutes-each-in-5-lines-or-less-of-r.html). ComputerWorld.com by Sharon Machlis]
4
+
Use the [`mapview` package](https://r-spatial.github.io/mapview/index.html) to make interactive maps. In this example, georeference Starbucks coffee shop locations in North Carolina (2012). (Adapted from Machlis.)^[[5 Visualizations in 5 Minutes](http://www.computerworld.com/article/2893271/business-intelligence/5-data-visualizations-in-5-minutes-each-in-5-lines-or-less-of-r.html). ComputerWorld.com by Sharon Machlis]
You can save a map as an interactive HTML page or a static `.png, .pdf, or .jpeg` file with the [`mapshot` function](https://r-spatial.github.io/mapview/reference/mapshot.html). For example:
Copy file name to clipboardExpand all lines: 02_choropleth.Rmd
+9-8Lines changed: 9 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1,37 +1,36 @@
1
1
---
2
2
title: "tidycensus"
3
-
output: html_document
4
3
---
5
4
6
-
The [tidycensus](https://walkerke.github.io/tidycensus/index.html) package, developed by [Kyle Walker](https://walkerke.github.io/), is very **convenient and easy to use package for making choropleth maps** from United States Department of **Census data**, specifically from the Decennial and ACS Census reports. This package makes it possible to gather census variables and conveniently join those variables with "Census Geography" (i.e. aka "shapefiles", or polygons.) Visualization, or plotting, maps can be done with separate packages.
5
+
The [tidycensus](https://walkerke.github.io/tidycensus/index.html) package, developed by [Kyle Walker](https://walkerke.github.io/), is very **convenient and easy to use package for making choropleth maps** from United States Department of **Census data**. Tidycensus uses the Decennial or ACS Census reports. This package makes it possible to gather census variables and conveniently join those variables with "Census Geography" (i.e. aka "shapefiles", or polygons.) Visualizationcan be done with separate packages such as `mapview`, `leaflet`, or `ggplot2::geom_sf()`.
7
6
8
7
9
8
```{r libraries, message=FALSE, warning=FALSE}
10
9
library(tidyverse)
11
10
library(sf)
12
11
library(tidycensus)
13
-
#library(leaflet)
14
12
library(mapview)
15
13
```
16
14
17
15
## Census API Key
18
16
19
-
Use the tidycensus package to gather Census data and join that data with Census geography (i.e. geometry, i.e. shapefiles, i.e. polygons). First, you will need to get a [free Census API key](https://api.census.gov/data/key_signup.html). Kyle Walker's [*Basic usage of tidycensus*](https://walkerke.github.io/tidycensus/articles/basic-usage.html) documents this process.
17
+
you need a [free Census API key](https://api.census.gov/data/key_signup.html). Kyle Walker's [*Basic usage of tidycensus*](https://walkerke.github.io/tidycensus/articles/basic-usage.html) documents this process.
20
18
21
19
```{}
22
20
census_api_key("YOUR API KEY GOES HERE")
23
21
```
24
22
25
23
### .Renviron File
26
24
27
-
See also Kyle's [more detailed documentation](https://walkerke.github.io/tidycensus/reference/census_api_key.html) for putting the key into your environment file. But skip that for the moment.
25
+
See also Kyle's [more detailed documentation](https://walkerke.github.io/tidycensus/reference/census_api_key.html) for caching the API key in your R environment.
28
26
29
27
30
28
## TidyCensus -- Get Data
31
29
32
-
Create a Simple Features dataframe using `tidycensus::get_acs()`
30
+
Create a Simple Features (i.e. `sf`) dataframe using `tidycensus::get_acs()`
33
31
34
32
The Census population variable we'll use is "B01003_001". More information about identifying Census variables is available at the [bottom of this page](#variables).
@@ -151,7 +152,7 @@ The Census is a very large collection of data. Many casual users of Census data
151
152
152
153
## Shapefiles
153
154
154
-
In the [*tmap* section](031_thematic_mapping.html) of the [Simple Features module](030_thematic_sf.html) we will use the `tigris` package to gather State level, Census geography shapefiles. Shapefiles are an important GIS data standard. There are many other standards, although shapefiles have a very broad user base. If you need shapefiles for other geographies, please consult our[*GIS Data: Starting Points* guide](https://guides.library.duke.edu/gisdata) -- a very handy collection of GIS data sources, much of which will be in the shapefiles format.
155
+
Shapefiles are an important GIS data standard used frequently in thematic mapping. There are many other standards, although shapefiles have a very broad user base. If you need shapefiles for other geographies, please consult the[*guide to geospatial applications using the R programming language*](https://guides.library.duke.edu/r-geospatial)
Copy file name to clipboardExpand all lines: 031_thematic_mapping.Rmd
+5-8Lines changed: 5 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,5 @@
1
1
---
2
2
title: "Thematic Mapping with tmap"
3
-
output: html_document
4
3
---
5
4
6
5
@@ -19,11 +18,11 @@ library(sf)
19
18
Using the `tigris` package, get Census Tiger shapefiles for census geographies. Tigris will return the shapefile in the `sf`, or simple features, format.
Copy file name to clipboardExpand all lines: 032_thematic_mapping_geom_sf.Rmd
+13-15Lines changed: 13 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,5 @@
1
1
---
2
2
title: "Thematic Mapping with geom_sf"
3
-
output: html_document
4
3
---
5
4
6
5
@@ -16,20 +15,19 @@ library(ggplot2)
16
15
17
16
## Shapefiles as sf
18
17
19
-
Repeating steps from the [previous section](031_thematic_mapping.html), using the `tigris` package, get Census Tiger shapefiles for census geographies. Coastal boundaries can be gathered with the tigris argument: `cb = TRUE`.
18
+
Use the `tigris` package to get Census Tiger shapefiles for census geographies. Coastal boundaries can be gathered with the tigris argument: `cb = TRUE`.
As mentioned before, the data are from the Bureau of Labor Statistics. These data are stored in an excel file in the `data` directory of the [repository](https://github.com/libjohn/mapping-with-R): `data/OES_Report.xlsx`.
31
-
32
-
Again, from the previous section you will see how these data were gathered, loaded, transformed, and joined.
30
+
In additon to shapefiles, the wage data used in this example comes from from the Bureau of Labor Statistics. These data are stored in an excel file in the `data` directory of the [repository](https://github.com/libjohn/mapping-with-R): `data/OES_Report.xlsx`.
33
31
34
32
```{r getblsdata, message=FALSE, warning=FALSE}
35
33
Salary4Helpers <-
@@ -42,7 +40,7 @@ Salary4Helpers
42
40
43
41
## Wrangle the data
44
42
45
-
As before...
43
+
Using the [`stringr` package](https://stringr.tidyverse.org) we can extract the text of the state names from the state code by leveraging regular expressions (i.e. regex) pattern matching techniques with stringr::str_extract().
In this section we introduce making shapefiles with ggplot2. ggplot2 is one of the more popular and broadly distributed graphics packages used in the R community. ([Learn more](https://rfun.library.duke.edu/#portfolio) about ggplot2.
80
+
ggplot2 is one of the more popular and broadly distributed graphics packages used in the R community. ([Learn more](https://rfun.library.duke.edu/#portfolio) about ggplot2.
83
81
84
-
In this plot I reversed the direction of the color scale. After consulting with my visualization colleagues it seems this may have been a non-standard action on my part. But, I leave the `direction`argument here for the curious.
82
+
In this plot I **reversed** the direction of the color scale. My visualization colleagues alerted me that this is non-standard approach to visualization, but I kept the argument in this example to demonstrate the `direction` argument.
85
83
86
-
Use a pleasing projection, in this case assigned the crs projection to '5070' (`coord_sf(crs = 5070)`), and removed the gridlines (i.e [graticules](https://en.wikipedia.org/wiki/Graticule)) `coords_sf(datum = NA)`
84
+
Use a pleasing [projection](https://guides.library.duke.edu/r-geospatial/CRS), in this case assigned the crs projection to '5070' (`coord_sf(crs = 5070)`), and removed the gridlines (i.e [graticules](https://en.wikipedia.org/wiki/Graticule)) `coords_sf(datum = NA)`
[Guide to geospatial applications using the R programming language](https://guides.library.duke.edu/r-geospatial)
11
+
12
+
[Code for Hands-on Workshop -- Spring 2019](https://github.com/libjohn/map-spring2019)
13
+
14
+
## Overview
15
+
16
+
These learning and quick-reference resource pages support the face-to-face workshop, [Mapping with R](https://rfun.library.duke.edu/portfolio/mapping_workshop/), offered via the [Data & Visualization Services](https://library.duke.edu/data/) Department, Duke University Libraries. The exercises and workshop are designed to help you learn georeferencing, make a [choropleth](https://en.wikipedia.org/wiki/Choropleth_map) with USA census data via the [tidycensus](https://walkerke.github.io/tidycensus/) package, and briefly introducing the [sf](http://r-spatial.github.io/sf/) package, simple features.
1. Georeferencing, Plotting XY latitude & longitude: with [interactive `mapview` maps](01_georeference.html) and saving static maps.
38
+
39
+
1. [Choropleths with tidycensus](02_choropleth.html)
40
+
41
+
1. [Thematic Mapping](030_thematic_sf.html) with `ggplot2`, `geom_sf`, `tigris`, and `viridis`. Additionally we show faceting mapping, and saving map images and files. We also introduce `tmap` a full featured thematic mapping package.
0 commit comments