pretty_rivers/03_make_figures.R

66 lines
1.5 KiB
R
Raw Normal View History

# load libraries
library(sf)
# 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
colors <- list(darkblue = "#062e57",
lightblue = "#b1dcf3",
lightgrey = "#6D6D6D")
2023-10-16 15:24:53 -05:00
# set dimensions of figures
width <- 8.5
height <- 11
units <- "in"
res <- 600
margin <- 0
# plot map
plot_map <- function () {
2023-10-16 16:54:10 -05:00
plot(sf::st_geometry(extent_poly),
col = colors$lightgrey,
2023-10-16 16:54:10 -05:00
border = "black")
plot(political$Wisconsin_State_Boundary_24K.geojson,
col = colors$darkblue,
border = NA,
add = TRUE)
2023-10-16 16:54:10 -05:00
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)
}
# save figure
tiff(filename = paste0(figure_dir,"/map.tiff"),
2023-10-16 16:54:10 -05:00
width = width,
height = height,
units = units,
res = res,
compression = "lzw")
2023-10-16 15:24:53 -05:00
par(mai=c(margin, margin, margin, margin))
par(mar=c(1,1,1,1))
plot_map()
dev.off()
png(filename = paste0(figure_dir, "/map.png"),
2023-10-16 16:54:10 -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))
plot_map()
dev.off()