From c25d799318ede7062b195796f323cde9b9b4d22b Mon Sep 17 00:00:00 2001
From: Kaysa Vaarre-Lamoureux <kvaarre-lamoureux@usgs.gov>
Date: Mon, 13 Jan 2025 14:30:06 -0500
Subject: [PATCH] plain text legend, gray for NA values

---
 findex/src/plot_utils.R | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/findex/src/plot_utils.R b/findex/src/plot_utils.R
index f5f7aa3..b8a41e8 100644
--- a/findex/src/plot_utils.R
+++ b/findex/src/plot_utils.R
@@ -19,22 +19,27 @@ threat_map <- ggplot()+
   geom_sf(data = filtered_df, aes(geometry = Shape, fill = MeanWeightedThreatMetric, color = MeanWeightedThreatMetric))+
   scale_fill_gradientn(
     colors = colorRampPalette(c(rev(unlist(pal))))(100),
-    limits = c(0, max(filtered_df$MeanWeightedThreatMetric)),
-    na.value=NA
+    limits = c(0, max(filtered_df$MeanWeightedThreatMetric, na.rm = T)),
+    na.value = "gray80",
+    breaks = c(0 + max(filtered_df$MeanWeightedThreatMetric, na.rm = T)/10, 
+               #max(habitat_data$MeanWeightedThreatMetric)/2, 
+               max(filtered_df$MeanWeightedThreatMetric, na.rm = T) - max(filtered_df$MeanWeightedThreatMetric, na.rm = T)/10),
+    labels = c("Lower", "Higher")
   )+
   scale_color_gradientn(
     colors = colorRampPalette(c(rev(unlist(pal))))(100), 
-    na.value=NA
+    na.value= "gray80"
   )+
   guides(color = "none")+
-  guides(fill = guide_colorbar(title.position = "top",
-                               direction = "vertical",
-                               barwidth = 1,
-                               barheight = 5))+
+  guides(fill = guide_colorbar(title = "Mean Threat",
+                               title.position = "top",
+                               direction = "horizontal",
+                               barwidth = 7,
+                               barheight = 1))+
   theme_void()+
   theme(
     legend.position = c(0.1, 0.21),
-    legend.title = element_blank()
+    legend.ticks = element_blank()
   )
 
 ggsave(out_file, height = 6, width = 10, dpi = 300) 
-- 
GitLab