changed figure margins
This commit is contained in:
parent
f6f22d5d97
commit
66392afe45
@ -1,6 +1,28 @@
|
|||||||
# load libraries
|
# load libraries
|
||||||
library(sf)
|
library(sf)
|
||||||
|
|
||||||
|
# reload extent data so you don't need to run the download data script again
|
||||||
|
data_dir <- "data"
|
||||||
|
nhdplusTools_data_dir(dir = paste0(data_dir, "/hydrologic"))
|
||||||
|
|
||||||
|
extent <- read.csv(file = "extent.csv")
|
||||||
|
crs <- 4269
|
||||||
|
|
||||||
|
extent_poly <- st_polygon(
|
||||||
|
x = list(
|
||||||
|
cbind(
|
||||||
|
extent$longitude[c(1,2,2,1,1)],
|
||||||
|
extent$latitude[c(1,1,2,2,1)])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
extent_poly <- st_sfc(extent_poly, crs=4326)
|
||||||
|
extent_bbox <- st_bbox(st_transform(x = extent_poly, crs))
|
||||||
|
extent <- list(longitude_max = max(extent$longitude),
|
||||||
|
longitude_min = min(extent$longitude),
|
||||||
|
latitude_max = max(extent$latitude),
|
||||||
|
latitude_min = min(extent$latitude))
|
||||||
|
|
||||||
# load and crop hydrologic data
|
# load and crop hydrologic data
|
||||||
data <- list(NULL)
|
data <- list(NULL)
|
||||||
sf_use_s2(FALSE)
|
sf_use_s2(FALSE)
|
||||||
|
@ -7,54 +7,54 @@ ifelse(!dir.exists(file.path(getwd(), figure_dir)), dir.create(file.path(getwd()
|
|||||||
|
|
||||||
# set colors
|
# set colors
|
||||||
colors <- list(darkblue = "#062e57",
|
colors <- list(darkblue = "#062e57",
|
||||||
lightblue = "#b1dcf3")
|
lightblue = "#b1dcf3")
|
||||||
|
|
||||||
|
# set dimensions of figures
|
||||||
|
width <- 8.5
|
||||||
|
height <- 11
|
||||||
|
units <- "in"
|
||||||
|
res <- 600
|
||||||
|
margin <- 0
|
||||||
|
|
||||||
|
|
||||||
# plot map
|
# plot map
|
||||||
plot_map <- function () {
|
plot_map <- function () {
|
||||||
plot(sf::st_geometry(extent_poly),
|
plot(sf::st_geometry(extent_poly),
|
||||||
col = colors$darkblue,
|
col = colors$darkblue,
|
||||||
extent = extent_bbox,
|
border = "black")
|
||||||
xlim = c(extent$longitude_min, extent$longitude_max),
|
plot(sf::st_geometry(data$NHDWaterbody),
|
||||||
ylim = c(extent$latitude_min, extent$latitude_max),
|
col = colors$lightblue,
|
||||||
border = "black")
|
border = NA,
|
||||||
plot(sf::st_geometry(data$NHDWaterbody),
|
add = TRUE)
|
||||||
col = colors$lightblue,
|
plot(sf::st_geometry(data$NHDArea),
|
||||||
border = NA,
|
col = colors$lightblue,
|
||||||
extent = extent_bbox,
|
border = NA,
|
||||||
xlim = c(extent$longitude_min, extent$longitude_max),
|
add = TRUE)
|
||||||
ylim = c(extent$latitude_min, extent$latitude_max),
|
plot(sf::st_geometry(data$NHDFlowline),
|
||||||
add = TRUE)
|
col = colors$lightblue,
|
||||||
plot(sf::st_geometry(data$NHDArea),
|
lwd = data$NHDFlowline$TotDASqKM^0.3204*0.0446,
|
||||||
col = colors$lightblue,
|
border = NA,
|
||||||
border = NA,
|
add = TRUE)
|
||||||
extent = extent_bbox,
|
|
||||||
xlim = c(extent$longitude_min, extent$longitude_max),
|
|
||||||
ylim = c(extent$latitude_min, extent$latitude_max),
|
|
||||||
add = TRUE)
|
|
||||||
plot(sf::st_geometry(data$NHDFlowline),
|
|
||||||
col = colors$lightblue,
|
|
||||||
lwd = data$NHDFlowline$TotDASqKM^0.3204*0.0446,
|
|
||||||
border = NA,
|
|
||||||
extent = extent_bbox,
|
|
||||||
xlim = c(extent$longitude_min, extent$longitude_max),
|
|
||||||
ylim = c(extent$latitude_min, extent$latitude_max),
|
|
||||||
add = TRUE)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# save figure
|
# save figure
|
||||||
tiff(filename = paste0(figure_dir,"/map.tiff"),
|
tiff(filename = paste0(figure_dir,"/map.tiff"),
|
||||||
width = 11,
|
width = width,
|
||||||
height = 17,
|
height = height,
|
||||||
units = "in",
|
units = units,
|
||||||
res = 600,
|
res = res,
|
||||||
compression = "lzw")
|
compression = "lzw")
|
||||||
|
par(mai=c(margin, margin, margin, margin))
|
||||||
|
par(mar=c(1,1,1,1))
|
||||||
plot_map()
|
plot_map()
|
||||||
dev.off()
|
dev.off()
|
||||||
|
|
||||||
png(filename = paste0(figure_dir, "/map.png"),
|
png(filename = paste0(figure_dir, "/map.png"),
|
||||||
width = 11,
|
width = width,
|
||||||
height = 17,
|
height = height,
|
||||||
units = "in",
|
units = units,
|
||||||
res = 600)
|
res = res)
|
||||||
|
par(mai=c(margin, margin, margin, margin))
|
||||||
|
par(mar=c(1,1,1,1))
|
||||||
plot_map()
|
plot_map()
|
||||||
dev.off()
|
dev.off()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user