Interacive spatial maps of the 2024 mass coral bleaching event (click on individual reefs for reef_name / label_ID and maximum DHW exposure during previous events 1998, 2002, 2016, 2017, 2020 & 2022):

library(tidyverse)
library(janitor)
library(sf)
library(stars)
library(raster)
library(tmap)
library(ggplot2)
library(terra)
library(tidyterra)


gbr_shape_dhw <- readRDS("/Users/rof011/GBR-coral-bleaching/data/gbr_shape_dhw.RDS")

gbr_shape_dhw_simple <- gbr_shape_dhw |> 
  st_simplify(preserveTopology = FALSE, dTolerance = 10)


gbr_shape_dhw_map <- gbr_shape_dhw_simple %>%
  mutate(across(where(is.numeric), round, digits = 1))


dhw_scale=c("#a5d3e5", "#eddf8c", "#ff9a15", "#820000")
breaks <- c(0, 4, 8, 12, 16, 20) # Modify this based on your needs
labels <- c("0", "4", "8", "12", "16", "20") # Modify labels accordingly

tm_basemap("Esri.WorldImagery") +
  tm_shape(gbr_shape_dhw_map) +
    tm_polygons(col="dhw_max_2024",  
              title="max DHW 2024", 
              palette = dhw_scale,
              style = "fixed",   
              #labels = labels,
              breaks=breaks,
              #midpoint=10,
              legend.show=TRUE,
              alpha=0.8, 
              popup.vars = c("dhw_max_1998", "dhw_max_2002", "dhw_max_2016", 
                             "dhw_max_2017", "dhw_max_2020", "dhw_max_2022", "dhw_max_2024")) + 
  tm_view(set.view = c(145.3, -14.5, 10))