Skip to content
Snippets Groups Projects
Commit 33ea32a0 authored by Vaarre-Lamoureux, Kaysa S's avatar Vaarre-Lamoureux, Kaysa S
Browse files

create thumbnail for findex global maps

parent 58188e2b
No related branches found
No related tags found
1 merge request!92Tweaks to findex global maps page
......@@ -277,6 +277,19 @@ p3 <- list(
knitr::plot_crop("../src/assets/images/all_threat_by_basin.png")
},
format = "file"
),
tar_target(
p3_top_threat_thumbnail,
top_threat_thumbnail(in_dat = p2_mean_weighted_threats,
threat_pal = p2_viz_config,
hybas_habitat_types = p2_hybas_habitat_types_sf,
proj = p1_proj,
threat_category = "none",
height = 6,
width = 6,
dpi = 300,
out_file = "../src/assets/images/threat_by_basin_thumbnail.png"),
format = "file"
)
# tar_target(
# p3_top_threat_legend_png,
......
......@@ -313,3 +313,42 @@ save_top_threat_legend <- function(plot, dpi, out_file){
knitr::plot_crop(out_file)
}
top_threat_thumbnail <- function(in_dat, threat_pal, hybas_habitat_types, proj, threat_category, height, width, dpi, out_file){
# these coordinates are NAD83 coordinates that correspond to "EPSG:4269", so will only work with the other data if they are also in "EPSG:4269"
bbox <- st_bbox(c(xmin = -25, xmax = 60, ymin = -35, ymax = 40))
# get bbox of projected area of interest
if (!(proj == "EPSG:4269")) {
bbox <- sf::st_as_sfc(bbox) |>
st_as_sf(crs = "EPSG:4269") |>
sf::st_transform(crs = proj) |>
sf::st_bbox()
}
# call custom plotting function
threat_map <- top_threat_plot(in_dat = in_dat,
threat_pal = threat_pal,
hybas_habitat_types = hybas_habitat_types,
proj = proj,
threat_category = threat_category) +
# crop for thumbnail
coord_sf(xlim = c(bbox['xmin'], bbox['xmax']),
ylim = c(bbox['ymin'], bbox['ymax']),
expand = F) +
# white background and add margin
theme(legend.position = "none",
plot.background = element_rect(fill = "white", color = NA),
panel.background = element_rect(fill = "white", color = NA),
plot.margin = margin(t = 2,
r = 2,
b = 2,
l = 2,
unit = "cm"))
# save in square ratio
ggsave(out_file,
threat_map, height = height, width = width, dpi = dpi)
}
src/assets/images/threat_by_basin_thumbnail.png

361 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment