Author

Carolyn Koehn

Load libraries:

Code
library(mapview)
library(sf)
library(terra)
library(tidyverse)

Load data:

Code
landmarks <- read_csv("/opt/data/data/assignment04/landmarks_ID.csv") %>%
  st_as_sf(., coords=c("longitude", "lattitude"), crs=4326)

fire.haz <- rast("/opt/data/data/assignment01/wildfire_hazard_agg.tif")

Interactivity with mapview:

Code
mapview(landmarks)
Code
mapview(raster::raster(fire.haz))

API with tidycensus:

Code
library(tidycensus)

v20 <- load_variables(2020, "acs5")

county_pop_white <- get_acs(geography = "county",
                            year = 2020,
                            variables = c("B02001_001", "B02001_002"),
                            state = "ID",
                            geometry = TRUE)

county_perc_white <- county_pop_white %>%
  st_make_valid(.) %>%
  filter(!st_is_empty(.)) %>%
  st_transform(., crs=st_crs(landmarks)) %>%
  dplyr::select(-moe) %>%
  pivot_wider(names_from = variable, values_from = estimate) %>%
  mutate(perc_white = B02001_002/B02001_001*100)

Interactivity with tmap:

Static map:

Code
library(tmap)

tm_shape(county_perc_white) +
  tm_polygons(col="perc_white")

Zoom map:

Code
tmap_mode("view")

tm_shape(county_perc_white) +
  tm_polygons(col="perc_white")

Change pop-up value:

Code
tm_shape(county_perc_white) +
  tm_polygons(col="perc_white", id = "perc_white")

Add layer:

Code
tm_shape(county_perc_white) +
  tm_polygons(col="perc_white") +
  tm_shape(landmarks) +
  tm_dots()

Change interactivity of different layers:

Code
tm_shape(county_perc_white) +
  tm_polygons(col="perc_white", interactive=FALSE) +
  tm_shape(landmarks) +
  tm_dots(id="FULLNAME")