Plot length frequency histogram with High Density Interval
plot_species_hdi.RdThis function takes a data frame and standardises its column names by converting them to lower case, replacing special characters with underscores, and ensuring that names are syntactically valid R names.
Examples
if (FALSE) { # \dontrun{
library(dplyr)
library(ggplot2)
library(ggdist)
# Minimal example data for one species
species_data <- tibble::tibble(
scientific_name = rep("Lutjanus sebae", 40),
length_mm = c(
rnorm(35, mean = 420, sd = 40),
rnorm(5, mean = 650, sd = 10)
)
)
# Maximum length lookup table
max_lengths <- tibble::tibble(
scientific_name = "Lutjanus sebae",
length_max_mm = 1000
)
# Temporary output directory
out_dir <- tempfile("hdi_plot_")
dir.create(out_dir)
out_dir <- paste0(out_dir, .Platform$file.sep)
# Run the function
plot_species_hdi(
species_data = species_data,
max_lengths = max_lengths,
dir = out_dir
)
} # }