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_ggmap_georef.Rmd
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ output: html_document
6
6
---
7
7
8
8
9
-
This page is deprecated. The `mapview` packages seems to do much of the same thing, and with less effort. Explore our introduction to the [plotting coordinates with mapview](01_georeference.html).
9
+
> This page is **deprecated**. The `mapview` packages deliveres much of the same functionality, and with less effort. Please explore the introduction to the [plotting coordinates with mapview](01_georeference.html).
10
10
11
11
Using the same data as in the [previous exercise](01_georeference.html), **build a static map quickly and easily using `ggmap`**. The `ggmap` package enables the integration of popular raster base-maps with ggplot2 syntax.
Copy file name to clipboardExpand all lines: 030_thematic_sf.Rmd
+6-10Lines changed: 6 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -10,35 +10,31 @@ output: html_document
10
10
11
11
1. Thematic Mapping with [sf & ggplot::geom_sf](032_thematic_mapping_geom_sf.html): creating choropleth with `ggplot2`, `sf`, and `viridis` packages
12
12
13
-
1.[Interactive thematic mapping](033_thematic_leaflet_example.html) with leaflet. This is largely a repeat of the Choropleth section (tidyverse), but focused on other interactive and stylistics features not previously discussed.
The initial modules of *Mapping in R* introduce plotting latitude and longitude with an interactive map (`leaflet`), a static map (`ggmap`), and generating a thematic map using `tidycensus.` The focus of this module is to introduce other customized thematic map packages: `tmap`, `sf`, `ggplot2`.
19
+
The initial modules of *Mapping in R* introduce plotting latitude and longitude with an interactive map (`mapview`) and generating a choropleth (a thematic map) using `tidycensus.` The focus of this module is to introduce other customized thematic map packages: `tmap`, `sf`, `ggplot2`.
22
20
23
-
**The backbone of this type of mapping data manipulation is the `sf` package** -- sf for simple features -- a modern tidyverse compatible package for encoding spatial vector data. `sf` is the successor to `sp`. Since `sf` is tidyverse compatible, among the advantages is the fact that you can see your numeric data in a more familiar (and easier-to-view) data frame .
21
+
**The backbone of this type of mapping data manipulation is the [`sf` package](https://r-spatial.github.io/sf/)** -- sf for simple features -- a modern tidyverse compatible package for encoding spatial vector data. `sf` is the successor to `sp`. Since `sf` is tidyverse compatible, among the advantages is the fact that you can see your numeric data in a more familiar (and easier-to-view) data frame .
24
22
25
23
> The `sf` simple features package affords the R coder an easy and familiar method of **storing data** vectors and **shapefile** polygons in a **tidy data frame**.
26
24
27
-
In these *Thematic Mapping with Simple Features* sections, we introduce the `tmap` package first. Through the the `tmap` package you will learn an easy-to-use package for building spatial distributions on geographic maps. These maps are typically `.png` image files. (.png files are easy to produce and share.) In this section we'll also use the `tigris` package -- to gather Census shapefiles -- and store those shape objects as in the Simple Features data structure. (In the [*Chropleth* module](02_choropleth.html) we used `tidycensus` to gather census Geography shape objects, as well as to gather census data variables.) `tigris` simply gathers the shapefile polygons. Later we will join the polygon object to a data frame using `tmaptools`.
25
+
In these *Thematic Mapping with Simple Features* sections, we introduce the `tmap` package first. Through the the `tmap` package you will learn an easy-to-use package for building spatial distributions on geographic maps. These maps are typically `.png` image files. (.png files are easy to produce and share.) In this section we'll also use the `tigris` package -- to gather Census shapefiles -- and store those shape objects in the Simple Features data structure. (In the [*Chropleth* module](02_choropleth.html) we used `tidycensus` to gather census Geography shape objects, as well as to gather census data variables.) `tigris` simply gathers the shapefile polygons. Later we will join the polygon object to a data frame using `tmaptools`.
28
26
29
27
Next, we'll use the `ggplot::geom_sf` function to create our mapping visualiations using the widely adopted ggplot2 syntax.
30
28
31
29
Later, in the *interactive thematic mapping* section, you will make a different interactive choropleth using `leaflet`. This section is largely a repeat of the earlier choropleth module. The level of interactivity is sparse, but functional. Interactivity demonstrates how you can generate maps which move beyond traditional 2D map-on-a-page images. Just know that this zoom-in/zoom-out interactivity feature is possible because we use `leaflet` to draw the map. By extension, you can add many interactive features, e.g. pop-up windows. This section is a good set-up for the last section which covers how to save maps as files.
32
30
33
-
[Sharing ouput files](036_thematic_mapping-outputs-fullwebpage.html), introduces the file saving techniques for saving maps. Even interactive maps can be shared and distributed. You can share maps either on the web, as an HTML file, or as [shapefile.](next.html#shapefiles)
31
+
[Saving / sharing ouput files](01_georeference.html#save_the_map). Even interactive maps can be shared and distributed. You can share maps either on the web, as an HTML file.
34
32
35
33
36
34
## Converting between `sf` and `sp`
37
35
38
36
`sf` is developed by the same [person](https://github.com/edzer)/people who developed `sp`. `sf` is the modern approach. However, if you need to convert between the two formats, it's easy! See [Reading, Writing and Converting Simple Features](https://r-spatial.github.io/sf/articles/sf2.html)
39
37
40
38
41
-
## Hands-on Exercises
42
39
43
-
Head over to the [exercises section](exercises.html) and practice making your own thematic map.
Copy file name to clipboardExpand all lines: 031_thematic_mapping.Rmd
+15-4Lines changed: 15 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -16,11 +16,10 @@ library(sf)
16
16
17
17
## Shapefiles as sf
18
18
19
-
Using the `tigris` package, get Census Tiger shapefiles for census geographies. Tigris will return the shapefile in the `sf`, or simple features, format. (See also, [more information on Shapefiles](02_choropleth.html#shapefiles).)
19
+
Using the `tigris` package, get Census Tiger shapefiles for census geographies. Tigris will return the shapefile in the `sf`, or simple features, format.
20
20
21
21
```{}
22
22
us_geo <- tigris::states(class = "sf")
23
-
# us_geo_spdf <- states() # spdf uses @data slots -- old school
The advantage of managing your spatial data as "Simple Features" (i.e. sf) over `sp` is that `sf` data can easily be viewed and manipulated as a rectangular data frame, before visualizing. `sp` is the predecessor to `sf`, but uses the old school @data slots method. If you're used to this it can be a highly functional data structure. But if you're inclined toward the tidyverse method, you'll see your data in a more familiar and easy-to-view format. Below are two methods of viewing the structure of the downloaded shapefiles.
32
+
The "Simple Features" (`sf`) data structure can easily be viewed and manipulated as a rectangular data frame, before visualizing. As an historical note -- an `sf` predecessor -- the `sp` data structure uses `@data` slots to hold data. We'll focus on the `sf` package. Below are two methods of viewing the structure of the downloaded shapefiles.
34
33
35
34
```{r data-structure}
36
35
class(us_geo)
@@ -46,6 +45,18 @@ And as noted, here's the data frame view. Notice the geometry (polygon shape) i
46
45
as_tibble(us_geo)
47
46
```
48
47
48
+
### Quick Plotting
49
+
50
+
If you want to see a very quick view of your mapping data, you can plot the geometry data with the `plot` function. In this case we use the `sf::st_geometry()` function to plot only the geometry. You can quickly generate a faceted map by excluding the `st_geometry` function: e.g. `plot(us_geo)` but that will consume computation cycles (i.e. wait time). Therefore, I recommend trying the smaller layer for now.
51
+
52
+
> **Note:** Census geography for the USA will span the globe in part becuase Region 9 includes a multitude of pacific islands. Later we will limit to simply the "lower 48" states.
53
+
54
+
```{r}
55
+
plot(st_geometry(us_geo))
56
+
```
57
+
58
+
59
+
49
60
## Get BLS data
50
61
51
62
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 [repository](https://github.com/libjohn/mapping-with-R): `data/OES_Report.xlsx`. **The goal is to attach this data to the previously downloaded shapefiles.**
@@ -147,7 +158,7 @@ Mark likes the USA_Contiguous_Albers_Equal_Area_Conic_USGS_version projection fo
Copy file name to clipboardExpand all lines: 032_thematic_mapping_geom_sf.Rmd
+2-4Lines changed: 2 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -90,17 +90,15 @@ contiguous_states %>%
90
90
91
91
## ggplot2 with geom_sf and viridis
92
92
93
-
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. I also reveresed 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.
93
+
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. I also 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. Finally, please note the easiest way to remove the [graticules](https://en.wikipedia.org/wiki/Graticule) is as follows: `coords_sf(datum = NA)`
94
94
95
95
```{r with-ggplot-geom_sf}
96
96
contiguous_states %>%
97
97
ggplot(aes(fill = wages, color = wages)) +
98
98
geom_sf() +
99
-
coord_sf(crs = 5070) +
99
+
coord_sf(crs = 5070, datum = NA) +
100
100
scale_fill_viridis(option = "viridis", direction = -1) +
101
101
scale_color_viridis(option = "viridis", direction = -1)
Copy file name to clipboardExpand all lines: 033_thematic_leaflet_example.Rmd
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,9 @@ output:
5
5
toc: FALSE
6
6
---
7
7
8
+
> This page is **deprecated**. The `mapview` packages deliveres much of the same functionality, and with less effort. Please explore the introduction to the [plotting coordinates with mapview](01_georeference.html).
> This page is **deprecated**. The `mapview` packages deliveres much of the same functionality, and with less effort. Please explore the introduction to the [saving maps with mapview](01_georeference.html#save_the_map).
8
+
6
9
On this page we demonstrate two methods of saving map files for sharing. The first method develops an interactive map that uses the entire web browser as the delivery mechanism. It's a nice way to maximize screen estate, a desirable feature for maps. The second method saves the file as a **shapefile**, a broadly portable file standard in GIS analysis.
7
10
8
11
Please note that I disabled some of the code chunks for efficiency of processing. The process documented below does work, despite reported feedback errors: [See the example output](mymap_sasw.html). This method should work for you as well, all the code is below. If you download this file from the repository, you'll need to make a simple change to the last two code chunks: re-insert the `r` into the curley braces in the last two code chunks.
Copy file name to clipboardExpand all lines: 039_facet_example.Rmd
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -23,4 +23,4 @@ Produced this faceted map
23
23
24
24

25
25
26
-
Full disclosure. The actual code was produced on the garbage-spaghetti plan. The quality of the code is not something I'm proud of. Therefore, I sanitized the code by showing the example, above. All the [actual code is available](038_facets_wrap_thematic_mapping.html). You can explore and/or reproduce this process from the actual code, as you see fit. If you don't mind, rewrite the code, using `purrr` then send me a cleaned and literate version. 'prec.
26
+
Full disclosure. The actual code was produced on the garbage-spaghetti plan. The quality of the code is not something I'm proud of. Therefore, I sanitized the code by showing the example, above. All the [actual code is available](038_facets_wrap_thematic_mapping.html). You can explore and/or reproduce this process from the actual code, as you see fit. (If you don't mind, rewrite the code, using `purrr` then send me a cleaned and literate version.)
0 commit comments