made data and figure directories easier to change

This commit is contained in:
Ben Varick 2023-10-16 13:59:59 -05:00
parent ced316e78f
commit 82fc901902
3 changed files with 17 additions and 5 deletions

View File

@ -3,7 +3,13 @@ library(nhdplusTools)
library(sf)
# set data dir
nhdplusTools_data_dir(dir = "data/hydrologic")
data_dir <- "data"
ifelse(
!dir.exists(file.path(getwd(), paste0(data_dir, "/hydrologic"))),
dir.create(file.path(getwd(), paste0(data_dir, "/hydrologic"), recursive = TRUE)),
FALSE)
nhdplusTools_data_dir(dir = paste0(data_dir, "/hydrologic"))
# load extent of map
extent <- read.csv(file = "extent.csv")

View File

@ -10,7 +10,7 @@ for (layer in layers){
# load political boundaries
political <- list(NULL)
political_boundaries <- list.files(path = "data/political_boundaries")
political_boundaries <- list.files(path = paste0(data_dir, "/political_boundaries"))
for (boundary in political_boundaries) {
political[[boundary]] <- st_read(paste0("data/political_boundaries/", boundary))
political[[boundary]] <- st_read(paste0(data_dir, "/political_boundaries/", boundary))
}

View File

@ -1,19 +1,24 @@
# 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")
# save figure
tiff(filename = "figures/map.tiff",
tiff(filename = paste0(figure_dir,"/map.tiff"),
width = 11,
height = 17,
units = "in",
res = 600,
compression = "lzw")
png(filename = "figures/map.png",
png(filename = paste0(figure_dir, "/map.png"),
width = 11,
height = 17,
units = "in",
@ -51,3 +56,4 @@ plot(sf::st_geometry(data$NHDFlowline),
add = TRUE)
# finish saving figure
dev.off()
dev.off()