added rscript 05_make_cnc_figures.R

This commit is contained in:
Ben Varick 2024-01-01 21:07:01 -06:00
parent d4aca67ed2
commit 1973e77d5f
Signed by: ben
SSH Key Fingerprint: SHA256:jWnpFDAcacYM5aPFpYRqlsamlDyKNpSj3jj+k4ojtUo
3 changed files with 78 additions and 6 deletions

View File

@ -11,13 +11,14 @@ colors <- list(darkblue = "#062e57",
lightgrey = "#6D6D6D")
# set dimensions of figures
width <- 8
height <- 10
width <- 10
height <- 8
units <- "in"
res <- 600
margin <- 0
# set state to highlight from political map
show_political <- FALSE
state <- c("Wisconsin")
# plot map
@ -29,10 +30,12 @@ plot_map <- function () {
col = colors$lightgrey,
border = NA,
add = TRUE)
if(show_political){
plot(sf::st_geometry(political[political$NAME_En %in% state, ]),
col = colors$darkblue,
border = NA,
add = TRUE)
}
plot(sf::st_geometry(data$NHDWaterbody),
col = colors$lightblue,
border = NA,

69
05_make_cnc_figures.R Normal file
View File

@ -0,0 +1,69 @@
# load libraries
library(sf)
library(tidyverse)
library(svglite)
# set dir to save figures to
figure_dir <- "figures"
ifelse(!dir.exists(file.path(getwd(), figure_dir)), dir.create(file.path(getwd(), figure_dir)), FALSE)
# set dimensions of figures
width <- 10
height <- 8
margin <- 0
# set state to highlight from political map
show_political <- FALSE
state <- c("Wisconsin")
# set lower threshold for displaying small lakes and streams
threshold_flowlines <- quantile(data$NHDFlowline$TotDASqKM, 0.80, na.rm = TRUE)
threshold_area <- quantile(data$NHDArea$AreaSqKM, 0.90, na.rm = TRUE)
threshold_waterbody <- quantile(data$NHDWaterbody$AreaSqKM, 0.90, na.rm = TRUE)
# plot map
plot_map <- function () {
plot(sf::st_geometry(extent_poly),
col = NA,
border = NA)
plot(sf::st_geometry(political$geometry),
col = NA,
border = "black",
add = TRUE)
if(show_political){
plot(sf::st_geometry(political[political$NAME_En %in% state, ]),
col = NA,
border = "black",
add = TRUE)
}
plot(sf::st_geometry(data$NHDWaterbody %>% filter(AreaSqKM > threshold_waterbody)),
col = "black",
border = NA,
add = TRUE)
plot(sf::st_geometry(data$NHDArea %>% filter(AreaSqKM > threshold_area)),
col = "black",
border = NA,
add = TRUE)
plot(sf::st_geometry(data$NHDFlowline %>% filter(TotDASqKM > threshold_flowlines)),
col = "black",
lwd = (data$NHDFlowline %>% filter(TotDASqKM > threshold_flowlines) %>% pull(TotDASqKM))^0.43*0.0446,
border = NA,
add = TRUE)
plot(sf::st_geometry(extent_poly),
col = NA,
border = "black",
lwd = 1,
add = TRUE)
}
## save figures
## generate tiff
svglite(filename = paste0(figure_dir,"/map.svg"),
width = width,
height = height)
par(mai=c(margin, margin, margin, margin))
par(mar=c(1,1,1,1))
plot_map()
dev.off()

View File

@ -1,3 +1,3 @@
latitude,longitude
47.73208,-93.55154
41.49273,-86.64896
48.50775,-124.91972
46.88398,-122.07015

1 latitude longitude
2 47.73208 48.50775 -93.55154 -124.91972
3 41.49273 46.88398 -86.64896 -122.07015