2023-10-16 12:17:24 -05:00
|
|
|
# load libraries
|
|
|
|
library(sf)
|
|
|
|
|
2023-10-16 13:59:59 -05:00
|
|
|
# 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 colors
|
2023-10-16 12:17:24 -05:00
|
|
|
colors <- list(darkblue = "#062e57",
|
2023-10-18 13:42:54 -05:00
|
|
|
lightblue = "#b1dcf3",
|
|
|
|
lightgrey = "#6D6D6D")
|
2023-10-16 15:24:53 -05:00
|
|
|
|
|
|
|
# set dimensions of figures
|
2023-10-18 11:31:09 -05:00
|
|
|
width <- 8
|
|
|
|
height <- 10
|
2023-10-16 15:24:53 -05:00
|
|
|
units <- "in"
|
|
|
|
res <- 600
|
|
|
|
margin <- 0
|
|
|
|
|
2023-10-29 15:13:00 -05:00
|
|
|
# set state to highlight from political map
|
2023-10-18 13:42:54 -05:00
|
|
|
state <- c("Wisconsin")
|
2023-10-16 12:17:24 -05:00
|
|
|
|
2023-10-16 14:17:18 -05:00
|
|
|
# plot map
|
|
|
|
plot_map <- function () {
|
2023-10-18 13:42:54 -05:00
|
|
|
plot(sf::st_geometry(extent_poly),
|
|
|
|
col = colors$lightblue,
|
|
|
|
border = NA)
|
|
|
|
plot(sf::st_geometry(political$geometry),
|
|
|
|
col = colors$lightgrey,
|
|
|
|
border = NA,
|
|
|
|
add = TRUE)
|
|
|
|
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,
|
|
|
|
add = TRUE)
|
|
|
|
plot(sf::st_geometry(data$NHDArea),
|
|
|
|
col = colors$lightblue,
|
|
|
|
border = NA,
|
|
|
|
add = TRUE)
|
|
|
|
plot(sf::st_geometry(data$NHDFlowline),
|
|
|
|
col = colors$lightblue,
|
|
|
|
lwd = data$NHDFlowline$TotDASqKM^0.3204*0.0446,
|
|
|
|
border = NA,
|
|
|
|
add = TRUE)
|
|
|
|
plot(sf::st_geometry(extent_poly),
|
|
|
|
col = NA,
|
|
|
|
border = "black",
|
|
|
|
lwd = 1,
|
|
|
|
add = TRUE)
|
2023-10-16 14:17:18 -05:00
|
|
|
}
|
2023-10-16 12:17:24 -05:00
|
|
|
|
2023-10-29 15:13:00 -05:00
|
|
|
## save figures
|
|
|
|
## generate tiff
|
2023-10-18 11:31:09 -05:00
|
|
|
# tiff(filename = paste0(figure_dir,"/map.tiff"),
|
|
|
|
# width = width,
|
|
|
|
# height = height,
|
|
|
|
# units = units,
|
|
|
|
# res = res,
|
|
|
|
# compression = "lzw")
|
|
|
|
# par(mai=c(margin, margin, margin, margin))
|
|
|
|
# par(mar=c(1,1,1,1))
|
|
|
|
# plot_map()
|
|
|
|
# dev.off()
|
|
|
|
#
|
2023-10-29 15:13:00 -05:00
|
|
|
## generate jpeg
|
2023-10-18 11:31:09 -05:00
|
|
|
# jpeg(filename = paste0(figure_dir,"/map.jpg"),
|
|
|
|
# width = width,
|
|
|
|
# height = height,
|
|
|
|
# units = units,
|
|
|
|
# res = res,
|
|
|
|
# quality = 93)
|
|
|
|
# par(mai=c(margin, margin, margin, margin))
|
|
|
|
# par(mar=c(1,1,1,1))
|
|
|
|
# plot_map()
|
|
|
|
# dev.off()
|
2023-10-16 12:17:24 -05:00
|
|
|
|
2023-10-29 15:13:00 -05:00
|
|
|
# generate png
|
2023-10-16 13:59:59 -05:00
|
|
|
png(filename = paste0(figure_dir, "/map.png"),
|
2023-10-18 13:42:54 -05:00
|
|
|
width = width,
|
|
|
|
height = height,
|
|
|
|
units = units,
|
|
|
|
res = res)
|
2023-10-16 15:24:53 -05:00
|
|
|
par(mai=c(margin, margin, margin, margin))
|
|
|
|
par(mar=c(1,1,1,1))
|
2023-10-16 14:17:18 -05:00
|
|
|
plot_map()
|
2023-10-16 12:17:24 -05:00
|
|
|
dev.off()
|