# ============================================================================ # Ecological impacts of temperature reductions in aquatic systems # Data analysis and visualisation for the systematic map # ============================================================================ # # This script reproduces the descriptive analyses, statistical models, and # figures used in the thesis. It assumes that the supplementary data file # "Master Thesis Data.xlsx" is stored in the current working directory. # # Notes # - One row in the data set represents one extracted biological response. # - PaperNr identifies the source study. # - EffectDirection == "N/A" is excluded from directional analyses. # - DeltaT is expressed in kelvin (K); absolute temperatures are in °C. # - The 3 K comparison is a predefined analytical comparison and is not a # statistically estimated biological breakpoint. # ============================================================================ # 1. Setup ------------------------------------------------------------------- required_packages <- c( "readxl", "dplyr", "tidyr", "ggplot2", "scales", "viridis", "RColorBrewer", "sf", "rnaturalearth", "shadowtext" ) missing_packages <- required_packages[ !vapply(required_packages, requireNamespace, logical(1), quietly = TRUE) ] if (length(missing_packages) > 0) { stop( "Install the following packages before running this script: ", paste(missing_packages, collapse = ", ") ) } library(readxl) library(dplyr) library(tidyr) library(ggplot2) input_file <- "Aquatic_Cooling_Systematic_Map_Data.xlsx" if (!file.exists(input_file)) { stop( "Input file not found: '", input_file, "'. Set the working directory to the folder containing the script and data." ) } data <- read_excel(input_file) required_columns <- c( "PaperNr", "Year", "Country", "TaxonomicGroup", "LifeStage", "Ecosystem", "ResponseCategory", "EffectDirection", "DeltaT", "BaselineTemp", "CoolingType", "DurationType" ) missing_columns <- setdiff(required_columns, names(data)) if (length(missing_columns) > 0) { stop( "The input file is missing required columns: ", paste(missing_columns, collapse = ", ") ) } # Common plotting theme theme_thesis <- function(base_size = 14) { theme_minimal(base_size = base_size) + theme( plot.title = element_text(size = 16, face = "bold", hjust = 0.5), axis.title = element_text(size = 14, face = "bold"), axis.text = element_text(size = 12, colour = "black"), panel.grid.minor = element_blank(), panel.grid.major.x = element_blank(), legend.position = "right", legend.title = element_text(face = "bold") ) } response_levels <- c("Mixed", "Negative", "Neutral", "Positive") taxon_levels <- c("Fish", "Mollusk", "Crustacean", "Insect", "Algae") response_category_levels <- c( "Survival", "Physiological Response", "Growth & Development", "Behavioral Response", "Reproductive Response", "Ecological / Population Response" ) # Helper: cluster-robust inference for a binomial GLM ------------------------- # # Multiple response records can originate from the same study. This function # calculates a study-clustered sandwich variance estimator with a finite-sample # correction. Inference uses t tests with G - 1 degrees of freedom, where G is # the number of study clusters. cluster_robust_glm <- function(model, cluster) { if (length(cluster) != nobs(model)) { stop("Length of 'cluster' must equal the number of observations in 'model'.") } X <- model.matrix(model) y <- model.response(model.frame(model)) mu <- fitted(model) w <- mu * (1 - mu) bread <- solve(crossprod(X, X * w)) cluster <- as.character(cluster) cluster_ids <- unique(cluster) cluster_scores <- lapply(cluster_ids, function(id) { idx <- cluster == id colSums(X[idx, , drop = FALSE] * (y[idx] - mu[idx])) }) cluster_scores <- do.call(rbind, cluster_scores) meat <- crossprod(cluster_scores) G <- length(cluster_ids) N <- nobs(model) K <- ncol(X) if (G <= 1) { stop("At least two study clusters are required.") } correction <- (G / (G - 1)) * ((N - 1) / (N - K)) vcov_cluster <- correction * bread %*% meat %*% bread robust_se <- sqrt(diag(vcov_cluster)) estimates <- coef(model) df <- G - 1 t_value <- estimates / robust_se p_value <- 2 * pt(abs(t_value), df = df, lower.tail = FALSE) t_critical <- qt(0.975, df = df) data.frame( Term = names(estimates), Estimate = unname(estimates), Cluster_Robust_SE = unname(robust_se), t = unname(t_value), df = df, p = unname(p_value), CI_lower = unname(estimates - t_critical * robust_se), CI_upper = unname(estimates + t_critical * robust_se), row.names = NULL ) } # Derived variables used in several analyses --------------------------------- data <- data %>% mutate( LifeStageGrouped = case_when( grepl("^Embryo$", LifeStage, ignore.case = TRUE) ~ "Embryo", grepl("Larva", LifeStage, ignore.case = TRUE) ~ "Larva", grepl("^Juvenile$", LifeStage, ignore.case = TRUE) ~ "Juvenile", grepl("^Adult$", LifeStage, ignore.case = TRUE) ~ "Adult", TRUE ~ "Others" ), LifeStageGrouped = factor( LifeStageGrouped, levels = c("Embryo", "Larva", "Juvenile", "Adult", "Others") ), TaxonomicGroup = factor(TaxonomicGroup, levels = taxon_levels), ResponseCategoryShort = gsub(" Response", "", ResponseCategory), DeltaClass = cut( DeltaT, breaks = c(0, 3, 6, 10, Inf), labels = c("0–3", ">3–6", ">6–10", ">10"), include.lowest = TRUE, right = TRUE ) ) # 2. Characteristics of the evidence base ------------------------------------ # 2.1 Publication trend (Fig. 3) pub_year <- data %>% distinct(PaperNr, Year) %>% count(Year, name = "Studies") %>% arrange(Year) %>% mutate(Cumulative = cumsum(Studies)) scale_factor <- max(pub_year$Cumulative) / max(pub_year$Studies) fig_publication_trend <- ggplot(pub_year, aes(x = Year)) + geom_col(aes(y = Studies), fill = "#2C7FB8", width = 0.7) + geom_line( aes(y = Cumulative / scale_factor), colour = "black", linewidth = 0.75, linetype = "dashed" ) + scale_y_continuous( name = "Number of Studies", sec.axis = sec_axis( ~ . * scale_factor, name = "Cumulative Number of Studies" ) ) + theme_thesis() + labs(title = "Publication Trend", x = "Year") print(fig_publication_trend) # Year(s) with the highest number of included studies pub_year %>% filter(Studies == max(Studies)) %>% print() # 2.2 Geographic distribution (Fig. 4) country_counts <- data %>% distinct(PaperNr, Country) %>% count(Country, name = "Studies") %>% mutate( Country = recode( Country, "USA" = "United States of America", "UK" = "United Kingdom" ) ) world <- rnaturalearth::ne_countries(scale = "medium", returnclass = "sf") world_data <- world %>% left_join(country_counts, by = c("name" = "Country")) top_countries <- world_data %>% filter(!is.na(Studies)) %>% slice_max(Studies, n = 10, with_ties = FALSE) %>% mutate( label_colour = if_else( Studies >= median(Studies), "white", "black" ) ) fig_geographic_distribution <- ggplot(world_data) + geom_sf(aes(fill = Studies), colour = "white", linewidth = 0.1) + shadowtext::geom_shadowtext( data = top_countries, aes(label = Studies, geometry = geometry, colour = label_colour), stat = "sf_coordinates", size = 3.5, bg.colour = "grey20", bg.r = 0.12, fontface = "bold" ) + scale_colour_identity() + viridis::scale_fill_viridis( option = "magma", trans = "log10", na.value = "grey90" ) + theme_void() + labs(title = "Geographic Distribution of Cold-Stress Studies", fill = "Studies") print(fig_geographic_distribution) # 2.3 Taxonomic coverage (Fig. 6) taxa <- data %>% distinct(PaperNr, TaxonomicGroup) %>% count(TaxonomicGroup, name = "Studies") fig_taxonomic_coverage <- ggplot( taxa, aes(x = reorder(TaxonomicGroup, Studies), y = Studies) ) + geom_col(fill = "#2C7FB8", width = 0.7) + geom_text( aes(y = Studies + 1, label = paste0("n = ", Studies)), size = 3, fontface = "bold", colour = "black", hjust = 0 ) + coord_flip() + scale_y_continuous(expand = expansion(mult = c(0, 0.15))) + theme_thesis() + labs(title = "Taxonomic Coverage", x = NULL, y = "Number of Studies") print(fig_taxonomic_coverage) # 2.4 Ecosystem representation (Fig. 5) ecosystem_counts <- data %>% distinct(PaperNr, Ecosystem) %>% count(Ecosystem, name = "Studies") fig_ecosystem_representation <- ggplot( ecosystem_counts, aes(x = Ecosystem, y = Studies, fill = Ecosystem) ) + geom_col(width = 0.6) + geom_text( aes(label = paste0("n = ", Studies)), vjust = 1.5, size = 3, fontface = "bold", colour = "black" ) + scale_fill_brewer(palette = "Set2") + theme_thesis() + theme(legend.position = "none") + labs(title = "Ecosystem Representation", x = NULL, y = "Number of Studies") print(fig_ecosystem_representation) # 2.5 Life-stage representation (Fig. 7) life_stage_counts <- data %>% distinct(PaperNr, LifeStageGrouped, TaxonomicGroup) %>% count(LifeStageGrouped, TaxonomicGroup, name = "Studies") life_stage_totals <- data %>% distinct(PaperNr, LifeStageGrouped) %>% count(LifeStageGrouped, name = "Studies") fig_life_stage <- ggplot( life_stage_counts, aes(x = LifeStageGrouped, y = Studies, fill = TaxonomicGroup) ) + geom_col( width = 0.6, colour = "white", linewidth = 0.3, position = position_stack(reverse = TRUE) ) + geom_text( data = life_stage_totals, aes(x = LifeStageGrouped, y = Studies, label = paste0("n = ", Studies)), inherit.aes = FALSE, vjust = -0.5, size = 3, fontface = "bold", colour = "black" ) + scale_fill_manual( values = c( "Fish" = "#2C7FB8", "Mollusk" = "#F28E2B", "Algae" = "#B07AA1", "Crustacean" = "#59A14F", "Insect" = "#E15759" ), drop = FALSE ) + scale_y_continuous(expand = expansion(mult = c(0, 0.15))) + theme_thesis() + labs( title = "Life Stage Representation", x = "Life Stage", y = "Number of Studies", fill = "Organism Group" ) print(fig_life_stage) # 3. Characteristics of cooling experiments --------------------------------- # 3.1 Distribution of cooling magnitudes (Fig. 10) fig_delta_distribution <- ggplot(data, aes(x = DeltaT)) + geom_histogram( binwidth = 2, boundary = 0, fill = "#2C7FB8", colour = "white", linewidth = 0.3, na.rm = TRUE ) + scale_x_continuous( breaks = seq(0, max(data$DeltaT, na.rm = TRUE), by = 2) ) + theme_thesis() + labs( title = "Distribution of Cooling Magnitudes", x = expression(Delta * T ~ "(K)"), y = "Number of Responses" ) print(fig_delta_distribution) # Cooling type: response records and underlying studies cooling_type_counts <- data %>% filter(!is.na(CoolingType)) %>% group_by(CoolingType) %>% summarise( Responses = n(), Studies = n_distinct(PaperNr), .groups = "drop" ) print(cooling_type_counts) # Cooling duration: response records and underlying studies duration_counts <- data %>% filter(!is.na(DurationType)) %>% group_by(DurationType) %>% summarise( Responses = n(), Studies = n_distinct(PaperNr), .groups = "drop" ) print(duration_counts) # 4. Biological responses to cooling ----------------------------------------- # 4.1 Biological response categories (Fig.8) response_counts <- data %>% count(ResponseCategoryShort, name = "Responses") fig_response_categories <- ggplot( response_counts, aes(x = reorder(ResponseCategoryShort, Responses), y = Responses) ) + geom_col(fill = "#2C7FB8", width = 0.7) + coord_flip() + scale_y_continuous( breaks = seq(0, max(response_counts$Responses), by = 25), expand = expansion(mult = c(0, 0.15)) ) + theme_thesis() + labs( title = "Biological Response Categories", x = NULL, y = "Number of Responses" ) print(fig_response_categories) # 4.2 Direction of biological responses (Fig. 9) response_direction <- data %>% filter(!is.na(EffectDirection), EffectDirection != "N/A") %>% count(ResponseCategory, EffectDirection, name = "Responses") %>% complete( ResponseCategory = response_category_levels, EffectDirection = response_levels, fill = list(Responses = 0) ) %>% mutate( ResponseCategory = factor( ResponseCategory, levels = rev(response_category_levels) ), EffectDirection = factor(EffectDirection, levels = response_levels) ) fig_response_direction <- ggplot( response_direction, aes(x = EffectDirection, y = ResponseCategory, fill = Responses) ) + geom_tile(colour = "white") + geom_text(aes(label = Responses), size = 5, fontface = "bold", colour = "white") + viridis::scale_fill_viridis(option = "plasma") + theme_thesis() + labs( title = "Direction of Biological Responses", x = "Effect Direction", y = "Response Category", fill = "Count" ) print(fig_response_direction) # 5. Influence of cooling magnitude on biological responses ------------------ # 5.1 Cooling-magnitude classes and biological responses (Fig. 11) delta_effect <- data %>% filter(!is.na(DeltaClass), !is.na(EffectDirection), EffectDirection != "N/A") %>% count(DeltaClass, EffectDirection, name = "Responses") %>% group_by(DeltaClass) %>% mutate(Percent = Responses / sum(Responses) * 100) %>% ungroup() %>% mutate(EffectDirection = factor(EffectDirection, levels = response_levels)) fig_delta_classes <- ggplot( delta_effect, aes(x = DeltaClass, y = Percent, fill = EffectDirection) ) + geom_col(width = 0.7, colour = "white") + geom_text( aes(label = Responses), position = position_stack(vjust = 0.5), size = 3, fontface = "bold", colour = "black" ) + scale_fill_brewer(palette = "Set2") + theme_thesis() + labs( title = expression(Delta * T ~ "vs Biological Response"), x = expression(Delta * T ~ "Class (K)"), y = "% Responses", fill = "Effect Direction" ) print(fig_delta_classes) # 5.2 Continuous relationship between DeltaT and negative responses (Fig. 12) reg_data <- data %>% filter( !is.na(DeltaT), !is.na(EffectDirection), EffectDirection != "N/A", !is.na(PaperNr) ) %>% mutate(NegativeResponse = as.integer(EffectDirection == "Negative")) glm_delta <- glm( NegativeResponse ~ DeltaT, data = reg_data, family = binomial(link = "logit") ) summary(glm_delta) # Conventional response-level inference beta_delta <- coef(glm_delta)["DeltaT"] se_delta <- summary(glm_delta)$coefficients["DeltaT", "Std. Error"] p_delta <- summary(glm_delta)$coefficients["DeltaT", "Pr(>|z|)"] ci_delta <- beta_delta + c(-1, 1) * qnorm(0.975) * se_delta odds_ratio_delta <- exp(beta_delta) # Study-clustered sensitivity analysis cluster_results <- cluster_robust_glm(glm_delta, reg_data$PaperNr) cluster_delta <- cluster_results %>% filter(Term == "DeltaT") cat( "\nResponse-level logistic regression\n", "----------------------------------\n", "beta = ", round(beta_delta, 4), "\n", "SE = ", round(se_delta, 4), "\n", "95% CI = ", round(ci_delta[1], 4), " to ", round(ci_delta[2], 4), "\n", "p-value = ", signif(p_delta, 4), "\n", "Odds ratio = ", round(odds_ratio_delta, 3), "\n", "\nStudy-clustered sensitivity analysis\n", "------------------------------------\n", "beta = ", round(cluster_delta$Estimate, 4), "\n", "Cluster-robust SE = ", round(cluster_delta$Cluster_Robust_SE, 4), "\n", "t(", cluster_delta$df, ") = ", round(cluster_delta$t, 3), "\n", "95% CI = ", round(cluster_delta$CI_lower, 4), " to ", round(cluster_delta$CI_upper, 4), "\n", "p-value = ", signif(cluster_delta$p, 4), "\n", "Number of study clusters = ", n_distinct(reg_data$PaperNr), "\n", sep = "" ) # The fitted curve and confidence band below are from the response-level GLM. # The annotation reports study-clustered inference for the DeltaT coefficient. stats_label <- paste0( "β = ", round(cluster_delta$Estimate, 3), "\np = ", round(cluster_delta$p, 3) ) fig_delta_logistic <- ggplot( reg_data, aes(x = DeltaT, y = NegativeResponse) ) + geom_jitter( width = 0.15, height = 0.05, alpha = 0.35, size = 2.5, colour = "#4D4D4D" ) + geom_smooth( method = "glm", method.args = list(family = binomial(link = "logit")), se = TRUE, linewidth = 1.3, colour = "#D55E00" ) + annotate( "text", x = max(reg_data$DeltaT, na.rm = TRUE) * 0.65, y = 0.2, label = stats_label, size = 5, fontface = "bold" ) + scale_x_continuous( breaks = seq(0, max(reg_data$DeltaT, na.rm = TRUE), by = 2), expand = expansion(mult = c(0.02, 0.05)) ) + scale_y_continuous( limits = c(0, 1), breaks = seq(0, 1, 0.25), labels = scales::percent ) + theme_thesis() + labs( title = "Effect of Cooling Magnitude on Negative Responses", x = expression(Delta * T ~ "(K)"), y = "Probability of Negative Response" ) print(fig_delta_logistic) # 5.3 Biological responses below and above the predefined 3 K reference value (Fig. 13) threshold_data <- data %>% filter( !is.na(DeltaT), !is.na(EffectDirection), EffectDirection != "N/A", !is.na(PaperNr) ) %>% mutate( FishGroup = if_else(TaxonomicGroup == "Fish", "Fish", "Non-fish"), Delta3 = if_else(DeltaT <= 3, "≤3 K", ">3 K"), NegativeResponse = as.integer(EffectDirection == "Negative") ) threshold_summary <- bind_rows( threshold_data %>% mutate(Group = "All taxa"), threshold_data %>% mutate(Group = FishGroup) ) %>% group_by(Group, Delta3) %>% summarise( n_responses = n(), n_studies = n_distinct(PaperNr), n_negative = sum(NegativeResponse), proportion_negative = mean(NegativeResponse), .groups = "drop" ) %>% mutate( Group = factor(Group, levels = c("All taxa", "Fish", "Non-fish")), Delta3 = factor(Delta3, levels = c("≤3 K", ">3 K")) ) print(threshold_summary) fig_threshold_3k <- ggplot( threshold_summary, aes(x = Group, y = proportion_negative, fill = Delta3) ) + geom_col(position = position_dodge(width = 0.8), width = 0.7) + geom_text( aes( label = paste0( n_negative, "/", n_responses, "\n(", scales::percent(proportion_negative, accuracy = 0.1), ")" ) ), position = position_dodge(width = 0.8), vjust = -0.35, size = 3.5 ) + scale_y_continuous( labels = scales::percent_format(accuracy = 1), limits = c(0, 0.8), expand = expansion(mult = c(0, 0.08)) ) + scale_fill_brewer(palette = "Set2") + theme_thesis() + theme(legend.position = "top") + labs( x = NULL, y = "Proportion of Negative Responses", fill = expression(Delta * T ~ "Class") ) print(fig_threshold_3k) # 5.4 Fish vs. non-fish comparison ------------------------------------------- fish_comparison <- data %>% mutate( FishGroup = if_else(TaxonomicGroup == "Fish", "Fish", "Non-fish") ) # Number of studies and response records fish_counts <- fish_comparison %>% group_by(FishGroup) %>% summarise( n_studies = n_distinct(PaperNr), n_responses = n(), .groups = "drop" ) print(fish_counts) # Ecosystem distribution by study fish_ecosystem <- fish_comparison %>% distinct(PaperNr, FishGroup, Ecosystem) %>% count(FishGroup, Ecosystem, name = "n_studies") %>% group_by(FishGroup) %>% mutate(proportion = n_studies / sum(n_studies)) %>% ungroup() print(fish_ecosystem) # Cooling magnitude by response record fish_delta_summary <- fish_comparison %>% filter(!is.na(DeltaT)) %>% group_by(FishGroup) %>% summarise( n_responses = n(), n_studies = n_distinct(PaperNr), median_DeltaT = median(DeltaT), mean_DeltaT = mean(DeltaT), min_DeltaT = min(DeltaT), max_DeltaT = max(DeltaT), Q1_DeltaT = quantile(DeltaT, 0.25), Q3_DeltaT = quantile(DeltaT, 0.75), .groups = "drop" ) print(fish_delta_summary, width = Inf) # Effect-direction distribution fish_effects <- fish_comparison %>% filter(!is.na(EffectDirection), EffectDirection != "N/A") %>% count(FishGroup, EffectDirection, name = "n") %>% group_by(FishGroup) %>% mutate(proportion = n / sum(n)) %>% ungroup() print(fish_effects) # Composition of the non-fish evidence base nonfish_taxa <- fish_comparison %>% filter(FishGroup == "Non-fish") %>% group_by(TaxonomicGroup) %>% summarise( n_studies = n_distinct(PaperNr), n_responses = n(), .groups = "drop" ) %>% arrange(desc(n_studies)) print(nonfish_taxa) # Study-level proportion of negative responses fish_study_effects <- fish_comparison %>% filter(!is.na(EffectDirection), EffectDirection != "N/A") %>% mutate(NegativeResponse = as.integer(EffectDirection == "Negative")) %>% group_by(PaperNr, FishGroup) %>% summarise( proportion_negative = mean(NegativeResponse), .groups = "drop" ) %>% group_by(FishGroup) %>% summarise( n_studies = n(), median_negative = median(proportion_negative), Q1_negative = quantile(proportion_negative, 0.25), Q3_negative = quantile(proportion_negative, 0.75), .groups = "drop" ) print(fish_study_effects) # Continuous DeltaT models for fish and non-fish fish_reg_data <- fish_comparison %>% filter( !is.na(DeltaT), !is.na(EffectDirection), EffectDirection != "N/A", !is.na(PaperNr) ) %>% mutate(NegativeResponse = as.integer(EffectDirection == "Negative")) fish_only_reg <- fish_reg_data %>% filter(FishGroup == "Fish") nonfish_only_reg <- fish_reg_data %>% filter(FishGroup == "Non-fish") glm_fish <- glm( NegativeResponse ~ DeltaT, data = fish_only_reg, family = binomial(link = "logit") ) glm_nonfish <- glm( NegativeResponse ~ DeltaT, data = nonfish_only_reg, family = binomial(link = "logit") ) summary(glm_fish) summary(glm_nonfish) # Cluster-adjusted inference for the fish model fish_cluster_results <- cluster_robust_glm(glm_fish, fish_only_reg$PaperNr) print(fish_cluster_results) # No formal fish-vs.-non-fish interaction test is used here. Separate # significance/non-significance in subgroup models must not be interpreted as # evidence that the DeltaT relationships differ statistically between groups. # 5.5 Fish-only comparison around 3 K ---------------------------------------- fish_threshold_data <- threshold_data %>% filter(FishGroup == "Fish") %>% mutate(Delta3 = factor(Delta3, levels = c("≤3 K", ">3 K"))) glm_fish_3k <- glm( NegativeResponse ~ Delta3, data = fish_threshold_data, family = binomial(link = "logit") ) summary(glm_fish_3k) fish_3k_cluster_results <- cluster_robust_glm( glm_fish_3k, fish_threshold_data$PaperNr ) %>% mutate( Odds_Ratio = exp(Estimate), OR_CI_lower = exp(CI_lower), OR_CI_upper = exp(CI_upper) ) print(fish_3k_cluster_results) # This binary comparison tests the predefined <=3 K vs. >3 K categories. # It does not estimate or demonstrate a breakpoint at exactly 3 K. # 6. Ecosystem-specific biological responses (Fig. 14) --------------------------------- freshwater_marine_response <- data %>% filter(!is.na(EffectDirection), EffectDirection != "N/A") %>% count(Ecosystem, EffectDirection, name = "Responses") %>% group_by(Ecosystem) %>% mutate(Percent = Responses / sum(Responses) * 100) %>% ungroup() %>% mutate(EffectDirection = factor(EffectDirection, levels = response_levels)) fig_ecosystem_response <- ggplot( freshwater_marine_response, aes(x = Ecosystem, y = Percent, fill = EffectDirection) ) + geom_col(width = 0.6, colour = "white") + geom_text( aes(label = Responses), position = position_stack(vjust = 0.5), size = 3, fontface = "bold", colour = "black" ) + scale_fill_brewer(palette = "Set2") + theme_thesis() + labs( title = "Ecosystem-specific Biological Responses", x = "Ecosystem", y = "% Responses", fill = "Effect Direction" ) print(fig_ecosystem_response) # 7. Supplementary analyses --------------------------------------------------- # 7.1 Cooling type and biological responses (Fig. S2, Appendix B) cooling_type_response <- data %>% filter( !is.na(CoolingType), CoolingType != "N/A", !is.na(EffectDirection), EffectDirection != "N/A" ) %>% count(CoolingType, EffectDirection, name = "Responses") %>% group_by(CoolingType) %>% mutate(Percent = Responses / sum(Responses) * 100) %>% ungroup() %>% mutate( CoolingType = factor( CoolingType, levels = c("Cold shock", "Acute cooling", "Gradual cooling", "Seasonal cooling") ), EffectDirection = factor(EffectDirection, levels = response_levels) ) fig_cooling_type <- ggplot( cooling_type_response, aes(x = CoolingType, y = Percent, fill = EffectDirection) ) + geom_col(width = 0.7, colour = "white") + geom_text( aes(label = Responses), position = position_stack(vjust = 0.5), size = 3, fontface = "bold", colour = "black" ) + scale_fill_brewer(palette = "Set2") + theme_thesis() + theme(axis.text.x = element_text(angle = 45, hjust = 1)) + labs( title = "Cooling Type and Biological Responses", x = "Cooling Type", y = "% Responses", fill = "Effect Direction" ) print(fig_cooling_type) # 7.2 Cooling duration and biological responses (Fig. S3, Appendix B) duration_response <- data %>% filter( !is.na(DurationType), DurationType != "N/A", !is.na(EffectDirection), EffectDirection != "N/A" ) %>% count(DurationType, EffectDirection, name = "Responses") %>% group_by(DurationType) %>% mutate(Percent = Responses / sum(Responses) * 100) %>% ungroup() %>% mutate( DurationType = factor( DurationType, levels = c( "Acute exposure", "Short-/medium-term exposure", "Chronic exposure" ) ), EffectDirection = factor(EffectDirection, levels = response_levels) ) fig_duration <- ggplot( duration_response, aes(x = DurationType, y = Percent, fill = EffectDirection) ) + geom_col(width = 0.6, colour = "white") + geom_text( aes(label = Responses), position = position_stack(vjust = 0.5), size = 3, fontface = "bold", colour = "black" ) + scale_fill_brewer(palette = "Set2") + theme_thesis() + theme(axis.text.x = element_text(angle = 25, hjust = 1, size = 11)) + labs( title = "Cooling Duration and Biological Responses", x = "Cooling Duration", y = "% Responses", fill = "Effect Direction" ) print(fig_duration) # 7.3 Starting temperature and response direction at DeltaT <= 5 K (Fig. S4, Appendix B) small_cooling <- data %>% filter( !is.na(BaselineTemp), !is.na(DeltaT), DeltaT >= 0, DeltaT <= 5, !is.na(EffectDirection), EffectDirection != "N/A" ) %>% mutate( ResponseDirection = if_else( EffectDirection == "Negative", "Negative", "Non-negative" ) ) cat( "\nResponses at DeltaT <= 5 K: ", nrow(small_cooling), "\n", "Underlying studies: ", n_distinct(small_cooling$PaperNr), "\n", sep = "" ) print(count(small_cooling, ResponseDirection)) fig_small_cooling <- ggplot( small_cooling, aes( x = BaselineTemp, y = DeltaT, colour = ResponseDirection, shape = ResponseDirection ) ) + geom_jitter(width = 0.25, height = 0.05, alpha = 0.7, size = 2.5) + geom_hline(yintercept = 3, linetype = "dashed", linewidth = 0.6) + scale_colour_manual( values = c("Negative" = "#D55E00", "Non-negative" = "#0072B2") ) + scale_shape_manual(values = c("Negative" = 16, "Non-negative" = 17)) + theme_classic(base_size = 12) + labs( title = "Biological Responses at Cooling Magnitudes ≤5 K", x = "Starting Temperature (°C)", y = expression(Delta * T ~ "(K)"), colour = "Response", shape = "Response" ) print(fig_small_cooling) # 7.4 Exploratory descriptive analysis around 2 K (Fig. S5, Appendix B) # # This analysis is retained because the corresponding visualisation is # included in the supplementary material. The 2 K value is used only for # descriptive comparison. It is not treated as a biological threshold, and # no inferential threshold test is performed. Directional analyses exclude # responses coded as N/A. small_2k_data <- data %>% filter( !is.na(DeltaT), !is.na(EffectDirection), EffectDirection != "N/A" ) %>% mutate( Delta2 = factor( if_else(DeltaT <= 2, "≤2 K", ">2 K"), levels = c("≤2 K", ">2 K") ), NegativeResponse = EffectDirection == "Negative" ) small_2k_summary <- small_2k_data %>% group_by(Delta2) %>% summarise( n_responses = n(), n_studies = n_distinct(PaperNr), n_negative = sum(NegativeResponse), proportion_negative = mean(NegativeResponse), .groups = "drop" ) print(small_2k_summary) fig_2k_descriptive <- ggplot( small_2k_summary, aes(x = Delta2, y = proportion_negative, fill = Delta2) ) + geom_col(width = 0.6) + geom_text( aes( label = paste0( n_negative, "/", n_responses, "\n(", scales::percent(proportion_negative, accuracy = 0.1), ")" ) ), vjust = -0.35, size = 3.5 ) + scale_y_continuous( labels = scales::percent_format(accuracy = 1), limits = c(0, 1), expand = expansion(mult = c(0, 0.08)) ) + scale_fill_brewer(palette = "Set2") + theme_thesis() + theme(legend.position = "none") + labs( title = expression("Exploratory Comparison Around " * Delta*T == 2 * " K"), x = expression(Delta*T~"Class"), y = "Proportion of Negative Responses" ) print(fig_2k_descriptive) # 7.5 Evidence-gap heatmap: taxonomic group x response category (Fig. S1, Appendix B) # Values represent the number of unique studies. evidence_gap <- data %>% filter( !is.na(TaxonomicGroup), !is.na(ResponseCategory), as.character(TaxonomicGroup) != "N/A", ResponseCategory != "N/A" ) %>% group_by(TaxonomicGroup, ResponseCategory) %>% summarise(Studies = n_distinct(PaperNr), .groups = "drop") %>% complete( TaxonomicGroup = factor(taxon_levels, levels = taxon_levels), ResponseCategory = response_category_levels, fill = list(Studies = 0) ) %>% mutate( TaxonomicGroup = factor(TaxonomicGroup, levels = taxon_levels), ResponseCategory = factor(ResponseCategory, levels = response_category_levels) ) print(evidence_gap) fig_evidence_gap <- ggplot( evidence_gap, aes(x = ResponseCategory, y = TaxonomicGroup, fill = Studies) ) + geom_tile(colour = "white", linewidth = 0.7) + geom_text(aes(label = Studies), size = 4) + viridis::scale_fill_viridis(option = "plasma", direction = 1, name = "Studies") + scale_x_discrete( labels = c( "Survival", "Physiological", "Growth &\nDevelopment", "Behavioral", "Reproductive", "Ecological /\nPopulation" ) ) + theme_thesis() + theme(axis.text.x = element_text(angle = 45, hjust = 1)) + labs( title = "Taxonomic and Biological Response Evidence Gaps", x = "Biological Response Category", y = "Taxonomic Group" ) print(fig_evidence_gap) # 8. Reproducibility information --------------------------------------------- cat("\nSession information\n") cat("===================\n") print(sessionInfo())