Skip to content

Commit 103a53d

Browse files
committed
Installing data projects
1 parent 3b0c524 commit 103a53d

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

_freeze/resources/mapping/execute-results/html.json

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

resources/mapping.qmd

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,39 @@ locations_sf
156156
Notice the differences between `locations` and `locations_sf`. The latter has combined the `long` and `lat` columns into a single `geometry` column, while we also get attributes about the object's CRS as shown above in @fig-sf.
157157

158158
### 3. Get a base map
159-
There are many packages that provide vector mapping data in R. [rnaturalearth](https://docs.ropensci.org/rnaturalearth/index.html) is a great starting point. It contains worldwide data for administrative boundaries and natural features such as lakes, rivers, and oceans. [tigris](https://github.com/walkerke/tigris) provides access to census bureau geographic data. In this example we will use [USAboundaries](https://docs.ropensci.org/USAboundaries/index.html), which provides contemporary and historical boundaries in the United states. Note that both rnaturalearth and USAboundaries provide most of the data through secondary packages. If these packages are needed, you will be prompted to install them. Both rnaturalearth and USAboundaries return `sf` objects with a CRS of EPSG:4326.
159+
There are many packages that provide vector mapping data in R. [rnaturalearth](https://docs.ropensci.org/rnaturalearth/index.html) is a great starting point. It contains worldwide data for administrative boundaries and natural features such as lakes, rivers, and oceans. [tigris](https://github.com/walkerke/tigris) provides access to census bureau geographic data. In this example we will use [USAboundaries](https://docs.ropensci.org/USAboundaries/index.html), which provides contemporary and historical boundaries in the United states. Both rnaturalearth and USAboundaries provide most of the data through secondary packages. If these packages are needed, you will be prompted to install them.
160160

161-
Here, we want county data for a single state.
161+
162+
::: {.callout-warning collapse=false}
163+
## Installing data packages on Windows
164+
If the installation fails on Windows with an error that the package cannot be built, there are two options to solve the issue.
165+
166+
1. Download and install [RTools](https://cran.r-project.org/bin/windows/Rtools/), which makes it possible to build packages.
167+
2. Install the package from a different repository:
168+
169+
```{r}
170+
#| eval: false
171+
install.packages("USAboundariesData", repos = c("https://ropensci.r-universe.dev"))
172+
```
173+
174+
The process is the same for rnaturalearth:
175+
176+
```{r}
177+
#| eval: false
178+
install.packages("rnaturalearth")
179+
install.packages("rnaturalearthdata", repos = c("https://ropensci.r-universe.dev"))
180+
install.packages("rnaturalearthhires", repos = c("https://ropensci.r-universe.dev"))
181+
```
182+
183+
:::
184+
185+
Both rnaturalearth and USAboundaries return `sf` objects with a CRS of EPSG:4326. Here, we want county data for a single state.
162186

163187
```{r}
164188
virginia <- us_counties(states = "Virginia")
165189
```
166190

191+
167192
### 4. Reproject the data
168193
Now we have the data, but we might want to change our data from using the web Mercator projection to a CRS that more accurately reflects the local area. USAboundaries provides both a data frame of the [State Plane Coordinate System](https://en.wikipedia.org/wiki/State_Plane_Coordinate_System) projections as EPSG codes and a function to quickly return the code for a state. We can then use `st_transform()` to reproject the data.
169194

0 commit comments

Comments
 (0)