diff --git a/R/figs.R b/R/figs.R index 8c2df2c..222739d 100644 --- a/R/figs.R +++ b/R/figs.R @@ -8,6 +8,8 @@ library(scales) library(tbeptools) library(ggspatial) library(sf) +library(forcats) +library(ggrepel) load(file = here('data/rstdatall.RData')) @@ -268,6 +270,64 @@ png(here('docs/figs/totalhmprecent.png'), height = 8, width = 7, family = 'serif print(pout) dev.off() +# current project total bar graph ------------------------------------------------------------- + +data(rstdatall) + +levs <- c("Artificial Reefs", "Coastal Uplands", "Forested Freshwater Wetlands", + "Hard Bottom", "Intertidal Estuarine\n(Other)", "Living Shorelines", + "Low-Salinity Salt Marsh", "Mangrove Forests", "Non-forested\nFreshwater Wetlands", + "Oyster Bars", "Salt Barrens", "Seagrasses", "Tidal Tributaries", "Uplands (Non-coastal)") + + +colfun <- colorRampPalette(brewer.pal(8, "Accent")) +col <- colfun(length(levs)) +names(col) <- levs + +toplo <- rstdatall %>% + filter(Year == cur) %>% + summarise( + cnt = n(), + .by = c('Primary', 'Year') + ) %>% + mutate( + Primary = case_when( + Primary == 'Non-forested Freshwater Wetlands' ~ 'Non-forested\nFreshwater Wetlands', + Primary == 'Intertidal Estuarine (Other)' ~ 'Intertidal Estuarine\n(Other)', + T ~ Primary + ), + Primary = factor(Primary), + Primary = fct_rev(fct_reorder(Primary, cnt)) + ) %>% + arrange(Primary) %>% + mutate( + cumcnt = rev(cumsum(rev(cnt))), + labloc = rev(diff(c(0, rev(cumcnt)))) / 2, + labadd = rev(lag(rev(cumcnt))), + labadd = ifelse(is.na(labadd), 0, labadd), + labloc = labloc + labadd + ) + +p <- ggplot(toplo, aes(x = Year, y = cnt, fill = Primary)) + + geom_col() + + scale_fill_manual(values = col) + + # scale_color_manual(values = col) + + scale_x_continuous( + expand = expansion(mult = 1) + ) + + theme_void() + + theme( + legend.position = 'none' + ) + + geom_text_repel(data = toplo[seq(1, nrow(toplo), by = 2), ], aes(label = Primary, x = Year + 0.45, y = labloc), hjust = 'left', + nudge_x = 0.25, direction = 'y', point.size = NA, size = 6.5) + + geom_text_repel(data = toplo[seq(2, nrow(toplo), by = 2), ], aes(label = Primary, x = Year - 0.45, y = labloc), hjust = 'right', + nudge_x = -0.25, direction = 'y', point.size = NA, size = 6.5) + +png(here('docs/figs/totalbar.png'), height = 6, width = 7, units = 'in', res = 500) +print(p) +dev.off() + # pie charts ---------------------------------------------------------------------------------- levs <- c("Artificial Reefs", "Coastal Uplands", "Forested Freshwater Wetlands", diff --git a/docs/figs/totalbar.png b/docs/figs/totalbar.png new file mode 100644 index 0000000..25f185a Binary files /dev/null and b/docs/figs/totalbar.png differ diff --git a/docs/summaries.html b/docs/summaries.html index 8e16400..53e3361 100644 --- a/docs/summaries.html +++ b/docs/summaries.html @@ -123,32 +123,32 @@
6 pro
Projects in Tampa Bay by primary habitat (2006-2023)
-
- +
+


Projects in Tampa Bay by general habitat (1971-2023)
-
- +
+


Projects in Tampa Bay by primary habitat (2023)
-
- +
+


Projects in Tampa Bay by general habitat (2023)
-
- +
+
@@ -225,13 +225,25 @@

+
+

Total 2023 as stacked barplot

+
+
+
+
+

+
+
+
+
+
-

+

@@ -242,7 +254,7 @@

-

+

@@ -625,7 +637,7 @@

- + diff --git a/docs/summaries.qmd b/docs/summaries.qmd index 0f95532..9a3e39b 100644 --- a/docs/summaries.qmd +++ b/docs/summaries.qmd @@ -116,6 +116,12 @@ knitr::include_graphics(here('docs/figs/barcur.png')) knitr::include_graphics(here('docs/figs/totalpie.png')) ``` +### Total `r cur` as stacked barplot + +```{r, out.width = '50%'} +knitr::include_graphics(here('docs/figs/totalbar.png')) +``` + ## Map ```{r}