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

move ggsave parameters to function call

parent 7776214e
No related branches found
No related tags found
1 merge request!86Findex global maps
...@@ -189,8 +189,8 @@ p3 <- list( ...@@ -189,8 +189,8 @@ p3 <- list(
subcat_habitat = NA, subcat_habitat = NA,
subcat_pollution = NA, subcat_pollution = NA,
subcat_climate = NA, subcat_climate = NA,
config_df = p2_viz_config config_df = p2_viz_config,
) height = 6, width = 10, dpi = 300)
}, },
format = "file", format = "file",
pattern = p2_threat_categories pattern = p2_threat_categories
...@@ -210,7 +210,8 @@ p3 <- list( ...@@ -210,7 +210,8 @@ p3 <- list(
subcat_pollution = NA, subcat_pollution = NA,
subcat_climate = NA, subcat_climate = NA,
in_dat = p2_mean_weighted_threats, in_dat = p2_mean_weighted_threats,
config_df = p2_viz_config) config_df = p2_viz_config,
height = 176, width = 429, unit = "px", dpi = 300)
}, },
pattern = p2_threat_categories pattern = p2_threat_categories
), ),
...@@ -229,7 +230,8 @@ p3 <- list( ...@@ -229,7 +230,8 @@ p3 <- list(
subcat_habitat = p2_habitat_subthreats, subcat_habitat = p2_habitat_subthreats,
subcat_pollution = p2_pollution_subthreats, subcat_pollution = p2_pollution_subthreats,
subcat_climate = p2_climate_subthreats, subcat_climate = p2_climate_subthreats,
config_df = p2_viz_config) config_df = p2_viz_config,
height = 6, width = 10, dpi = 300)
}, },
format = "file", format = "file",
pattern = p2_threat_subcategories pattern = p2_threat_subcategories
...@@ -249,7 +251,8 @@ p3 <- list( ...@@ -249,7 +251,8 @@ p3 <- list(
subcat_pollution = p2_pollution_subthreats, subcat_pollution = p2_pollution_subthreats,
subcat_climate = p2_climate_subthreats, subcat_climate = p2_climate_subthreats,
in_dat = p2_mean_weighted_subThreats, in_dat = p2_mean_weighted_subThreats,
config_df = p2_viz_config) config_df = p2_viz_config,
height = 176, width = 429, unit = "px", dpi = 300)
}, },
format = "file", format = "file",
pattern = p2_threat_subcategories pattern = p2_threat_subcategories
......
...@@ -70,7 +70,7 @@ subThreat_map <- function(in_dat, threat_category, threat_pal, proj, hybas_habit ...@@ -70,7 +70,7 @@ subThreat_map <- function(in_dat, threat_category, threat_pal, proj, hybas_habit
} }
cowplot_legend <- function(in_dat, legend_png, threat_category, out_file){ cowplot_legend <- function(in_dat, legend_png, threat_category, out_file, height, width, unit, dpi){
threat_df <- in_dat |> threat_df <- in_dat |>
filter(ThreatCategory == threat_category) filter(ThreatCategory == threat_category)
...@@ -126,11 +126,11 @@ cowplot_legend <- function(in_dat, legend_png, threat_category, out_file){ ...@@ -126,11 +126,11 @@ cowplot_legend <- function(in_dat, legend_png, threat_category, out_file){
color = "gray50", color = "gray50",
size = 9) size = 9)
#429x176 #429x176
ggsave(out_file, final_legend, height = 176, width = 429, units = "px", dpi = 300, bg = "transparent") ggsave(out_file, final_legend, height = height, width = width, units = unit, dpi = dpi, bg = "transparent")
} }
# plot = final_plot, in_dat = p2_mean_weighted_threats # height = 176, width = 429, unit = "px", dpi = 300
save_legend <- function(type, plot, threat_category, subcat_habitat, subcat_pollution, subcat_climate, in_dat, config_df){ save_legend <- function(type, plot, threat_category, subcat_habitat, subcat_pollution, subcat_climate, in_dat, config_df, height, width, unit, dpi){
if(type == "threat"){ if(type == "threat"){
name_conv <- config_df |> name_conv <- config_df |>
...@@ -141,12 +141,13 @@ save_legend <- function(type, plot, threat_category, subcat_habitat, subcat_poll ...@@ -141,12 +141,13 @@ save_legend <- function(type, plot, threat_category, subcat_habitat, subcat_poll
out_file <- sprintf(unique(name_conv$threat_legend_raw), str_replace_all(threat_category, " ", "_")) out_file <- sprintf(unique(name_conv$threat_legend_raw), str_replace_all(threat_category, " ", "_"))
ggsave(out_file, ggsave(out_file,
plot_legend, dpi = 300, bg = "transparent") plot_legend, dpi = dpi, bg = "transparent")
knitr::plot_crop(out_file) knitr::plot_crop(out_file)
out_file_final <- sprintf(unique(name_conv$threat_legend), str_replace_all(threat_category, " ", "_")) out_file_final <- sprintf(unique(name_conv$threat_legend), str_replace_all(threat_category, " ", "_"))
cowplot_legend(in_dat = in_dat, legend_png = out_file, threat_category = threat_category, out_file = out_file_final) cowplot_legend(in_dat = in_dat, legend_png = out_file, threat_category = threat_category,
out_file = out_file_final, height = height, width = width, unit = unit, dpi = dpi)
return(out_file_final) return(out_file_final)
...@@ -159,19 +160,20 @@ save_legend <- function(type, plot, threat_category, subcat_habitat, subcat_poll ...@@ -159,19 +160,20 @@ save_legend <- function(type, plot, threat_category, subcat_habitat, subcat_poll
out_file <- sprintf(unique(name_conv$subThreat_legend_raw), str_replace_all(threat_category, " ", "_")) out_file <- sprintf(unique(name_conv$subThreat_legend_raw), str_replace_all(threat_category, " ", "_"))
ggsave(out_file, ggsave(out_file,
plot_legend, dpi = 300, bg = "transparent") plot_legend, dpi = dpi, bg = "transparent")
knitr::plot_crop(out_file) knitr::plot_crop(out_file)
out_file_final <- sprintf(unique(name_conv$subThreat_legend), str_replace_all(threat_category, " ", "_")) out_file_final <- sprintf(unique(name_conv$subThreat_legend), str_replace_all(threat_category, " ", "_"))
cowplot_legend(in_dat = in_dat, legend_png = out_file, threat_category = threat_category, out_file = out_file_final) cowplot_legend(in_dat = in_dat, legend_png = out_file, threat_category = threat_category,
out_file = out_file_final, height = 176, width = 429, unit = "px", dpi = dpi)
return(out_file_final) return(out_file_final)
} }
} }
save_map <- function(type, plot, threat_category, subcat_habitat, subcat_pollution, subcat_climate, config_df){ save_map <- function(type, plot, threat_category, subcat_habitat, subcat_pollution, subcat_climate, config_df, height, width, dpi){
if(type == "threat"){ if(type == "threat"){
name_conv <- config_df |> name_conv <- config_df |>
...@@ -180,7 +182,7 @@ save_map <- function(type, plot, threat_category, subcat_habitat, subcat_polluti ...@@ -180,7 +182,7 @@ save_map <- function(type, plot, threat_category, subcat_habitat, subcat_polluti
out_file <- sprintf(unique(name_conv$threat_map), str_replace_all(threat_category, " ", "_")) out_file <- sprintf(unique(name_conv$threat_map), str_replace_all(threat_category, " ", "_"))
ggsave(out_file, ggsave(out_file,
plot, height = 6, width = 10, dpi = 300) plot, height = height, width = width, dpi = dpi)
} else if(type == "subThreat"){ } else if(type == "subThreat"){
name_conv <- config_df |> name_conv <- config_df |>
...@@ -189,7 +191,7 @@ save_map <- function(type, plot, threat_category, subcat_habitat, subcat_polluti ...@@ -189,7 +191,7 @@ save_map <- function(type, plot, threat_category, subcat_habitat, subcat_polluti
out_file <- sprintf(unique(name_conv$subThreat_map), str_replace_all(threat_category, " ", "_")) out_file <- sprintf(unique(name_conv$subThreat_map), str_replace_all(threat_category, " ", "_"))
ggsave(out_file, ggsave(out_file,
plot, height = 6, width = 10, dpi = 300) plot, height = height, width = width, dpi = dpi)
} }
} }
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