Skip to content

Commit

Permalink
banner of announcements added
Browse files Browse the repository at this point in the history
  • Loading branch information
tmieno2 committed Sep 25, 2024
1 parent 3963429 commit 62de67f
Show file tree
Hide file tree
Showing 477 changed files with 10,300 additions and 9,615 deletions.
2 changes: 0 additions & 2 deletions 01_Demonstration.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ setwd(here())
#--- load packages ---#
library(data.table)
library(here)
library(rgdal)
library(stringr)
library(rgeos)
library(sf)
library(ggplot2)
library(raster)
Expand Down
1 change: 0 additions & 1 deletion 01_z03_landuse_weather.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ pacman::p_load(
modelsummary, # regression table generation
future.apply, # parallel computation
cdlTools, # download CDL data
rgdal, # required for cdlTools
prism, # download PRISM data
stringr # string manipulation
)
Expand Down
4 changes: 3 additions & 1 deletion 01_z06_nunn_2008.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ pacman::p_load(
tidyverse, # data wrangling
units,
rmapshaper,
patchwork,
lwgeom,
ggplot2,
tictoc
)
```
Expand Down Expand Up @@ -153,7 +155,7 @@ However, what we need is the end point of the lines. We can use `lwgeom::st_endp
closest_pt_on_coast <- lwgeom::st_endpoint(minum_dist_to_coast)
```

The end points are represented as blue points in the figure below.
The end points are represented as blue points in the figure below.

```{r endpoint-africa-nunn08}
g_min_dist_line +
Expand Down
1 change: 1 addition & 0 deletions 01_z08_alsan_2015.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ weather <-
Let's subset `weather` to Africa and then calculate tsetse.

```{r}
sf_use_s2(FALSE)
weather_africa <-
#--- subset to Africa ---#
weather[tribes] %>%
Expand Down
16 changes: 11 additions & 5 deletions 02_VectorDataBasics.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
library(knitr)
knitr::opts_chunk$set(
echo = TRUE,
# cache = TRUE,
cache = TRUE,
comment = NA,
message = FALSE,
warning = FALSE,
Expand All @@ -26,9 +26,7 @@ setwd(here())
#--- load packages ---#
library(data.table)
library(here)
library(rgdal)
library(stringr)
library(rgeos)
library(sf)
library(ggplot2)
library(leaflet)
Expand Down Expand Up @@ -986,7 +984,7 @@ Sometimes, a vector data is excessively detailed for your purpose. For example,
Here, we use IL County borders for illustration.

```{r}
IL_counties <- st_read("Data/IL_county_detailed.geojson")
IL_counties <- tigris::counties(state = "Illinois", cb = TRUE, progress_bar = FALSE)
```

Here is the object size of `IL_counties`.
Expand All @@ -1006,36 +1004,43 @@ ggplot(IL_counties) +
However, if you focus on a single county, you can see that county borders in this data are fairly detaield. Let's look at the Cook county.

```{r g-cook}
Cook <- filter(IL_counties, NAME == "Cook County")
#| eval: false
Cook <- filter(IL_counties, NAME == "Cook")
(
g_cook_original <-
ggplot(Cook) +
geom_sf() +
coord_sf(lims_method = "geometry_bbox") +
theme_void()
)
```

You can see that its border with Lake Michigan has lots of non-linear segments. Let's simplify this using `st_simplify()`. We can use the `dTolerance` option to specify the degree of simplification.

```{r g-cook-simplified}
#| eval: false
Cook_simplify <- st_simplify(Cook, dTolerance = 1000)
g_cook_simplified <-
ggplot(Cook_simplify) +
geom_sf() +
coord_sf(lims_method = "geometry_bbox") +
theme_void()
```

The figure below compares the original (left) and simplified (right) versions.

```{r g-cook-both}
#| cache: false
#| eval: false
g_cook_original | g_cook_simplified
```

Let's now simplify `IL_counties` using `st_simplify()` to make its map light-weight.

```{r g-IL-simplified}
#| eval: false
IL_counties_simplified <- st_simplify(IL_counties, dTolerance = 1000)
ggplot(IL_counties_simplified) +
Expand All @@ -1046,6 +1051,7 @@ ggplot(IL_counties_simplified) +
You probably notice we now have some gaps between some counties. This is because `st_simplify()` does not respect the internal borders. To simplify only the outer borders, you can use `rmapshaper::ms_simplify()`. The `keep` option controls the degree of simplifcation (the lower, the more simplified).

```{r g-IL-simplified-fixed}
#| eval: false
IL_counties_mssimplified <- rmapshaper::ms_simplify(IL_counties, keep = 0.01)
ggplot(IL_counties_mssimplified) +
Expand Down
6 changes: 2 additions & 4 deletions 03_SpatialInteractionVectorVector.Rmd
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Spatial Interactions of Vector Data: Subsetting and Joining {#int-vv}

```{r chap3_setup, include = FALSE}
```{r chap3_setup, include = FALSE, cache = FALSE}
library(tufte)
library(knitr)
knitr::opts_chunk$set(
echo = TRUE,
# cache = TRUE,
cache = TRUE,
comment = NA,
message = FALSE,
warning = FALSE,
Expand All @@ -24,10 +24,8 @@ setwd(here())
```{r, include = FALSE, cache = FALSE}
#--- load packages ---#
library(data.table)
library(rgdal)
library(exactextractr)
library(stringr)
library(rgeos)
library(sf)
library(ggplot2)
library(raster)
Expand Down
3 changes: 3 additions & 0 deletions 05_SpatialInteractionVectorRaster.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,9 @@ prism_tmax_stack_5 <-
prism_tmax_0701_KS_sr_10,
prism_tmax_0701_KS_sr_10
)
set.names(prism_tmax_stack_5, paste0("layer_", 1:5))
temp <-
exact_extract(
prism_tmax_stack_5,
Expand Down
34 changes: 17 additions & 17 deletions 06_SpeedThingsUp.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,20 @@ knitr::opts_chunk$set(

```{r, echo=FALSE, warning=FALSE, cache = FALSE}
#--- load packages ---#
suppressMessages(library(data.table))
suppressMessages(library(exactextractr))
suppressMessages(library(prism))
suppressMessages(library(sf))
suppressMessages(library(terra))
suppressMessages(library(raster))
suppressMessages(library(tidyverse))
suppressMessages(library(DT))
suppressMessages(library(tictoc))
suppressMessages(library(tmap))
suppressMessages(library(future.apply))
suppressMessages(library(parallel))
suppressMessages(library(maps))
suppressMessages(library(bench))
suppressMessages(library(stringr))
library(data.table)
library(exactextractr)
library(prism)
library(sf)
library(terra)
library(raster)
library(tidyverse)
library(DT)
library(tictoc)
library(tmap)
library(future.apply)
library(parallel)
library(maps)
library(stringr)
```

## Before you start {-}
Expand Down Expand Up @@ -475,11 +474,12 @@ You can download all the prism files from [here](https://www.dropbox.com/sh/gkpr

```{r US_county, cache = TRUE}
(
US_county <- st_as_sf(map(database = "county", plot = FALSE, fill = TRUE)) %>%
US_county <-
st_as_sf(maps::map(database = "county", plot = FALSE, fill = TRUE)) %>%
#--- get state name from ID ---#
mutate(state = str_split(ID, ",") %>% lapply(., `[[`, 1) %>% unlist()) %>%
#--- project to the CRS of the CDL data ---#
st_transform(projection(brick("Data/PRISM/PRISM_ppt_y2017_m7.tif")))
st_transform(projection(brick("Data/PRISM/PRISM_ppt_y1990_m12.tif")))
)
```

Expand Down
Loading

0 comments on commit 62de67f

Please sign in to comment.