Created
May 11, 2020 21:01
-
-
Save joelnitta/811a6e86e6cfe618485c080cf99ad8de to your computer and use it in GitHub Desktop.
combine diversity metrics from different HUCs and get area
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set working directory | |
setwd(here::here()) | |
# Load packages and functions | |
source("r-code/01_start_up.R") | |
# Load plan | |
source("r-code/plan.R") | |
# Load cache | |
fish_cache <- new_cache("fish_cache") | |
# Load data | |
loadd(fish_biodiv_map_data, cache = fish_cache) | |
loadd(fish_biodiv_map_data_HUC6, cache = fish_cache) | |
loadd(fish_biodiv_map_data_HUC4, cache = fish_cache) | |
loadd(fish_biodiv_map_data_HUC2, cache = fish_cache) | |
# Define function to get area in KM and drop the geometry column | |
add_area <- function (x) { | |
dplyr::mutate(x, area_km = sf::st_area(geometry) %>% units::set_units(km^2) %>% as.numeric) %>% | |
dplyr::select(-geometry) | |
} | |
# Combine all datasets while getting area in sq km for each | |
fish_biodiv_map_data_combined <- bind_rows( | |
add_area(fish_biodiv_map_data), | |
add_area(fish_biodiv_map_data_HUC6), | |
add_area(fish_biodiv_map_data_HUC4), | |
add_area(fish_biodiv_map_data_HUC2) | |
) | |
saveRDS(fish_biodiv_map_data_combined, "temp/fish_biodiv_map_data_combined_2020-05-12.RDS") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment