Created
October 10, 2025 14:55
-
-
Save simbamangu/10e673132189d69771d5f646c8ca7f28 to your computer and use it in GitHub Desktop.
Trend graphs for DS2024 wildlife survey
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Trends | |
| library(tidyverse) | |
| library(janitor) | |
| library(readxl) | |
| tt <- read_excel("~/Downloads/Botswana NG23-NG16 2018-2022.xlsx") %>% | |
| clean_names() | |
| sptrend <- function(data, species_name, stratum_name) { | |
| data %>% | |
| filter(species == species_name, stratum == stratum_name) %>% | |
| ggplot(aes(x = survey, y = estimate)) + | |
| geom_line(colour = 'gray', | |
| lwd = 1.5, | |
| lty = 2) + | |
| geom_point(cex = 3) + | |
| scale_y_continuous(limits = c(0, NA)) + | |
| geom_errorbar(aes(ymin = estimate - std_error, ymax = estimate + std_error), | |
| width = 0.1) + | |
| ggtitle(paste(str_to_title(species_name), "-", stratum_name)) + | |
| labs(x = "Year", y = "Estimate") + | |
| theme_gray() | |
| } | |
| spplist = c( | |
| "elephant", | |
| "giraffe", | |
| "buffalo", | |
| "bushpig", | |
| "hippopotamus", | |
| "impala", | |
| "kudu", | |
| "lechwe", | |
| "reedbuck", | |
| "sitatunga", | |
| "steenbuck", | |
| "warthog", | |
| "waterbuck", | |
| "wildebeest", | |
| "zebra" | |
| ) | |
| for (sp in unique(spplist)) { | |
| for(strat in c("NG16", "NG23")){ | |
| cat(sp, " ", strat, " ") | |
| fig <- sptrend(tt, sp, strat) | |
| filename <- paste0("_report/_figures/", gsub(" ", "_", sp), "_", strat, ".pdf") | |
| ggsave(filename, width = 4, height = 3) | |
| cat("OK\n") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment