# load packages for data import, cleaning, and visualization
library(tidyverse)
library(here)
library(ggbeeswarm)
library(skimr)
library(janitor)
# import the original endangered species dataset
endangeredSpecies <- read_csv(here("data", "endangeredSpecies.csv"))
# standardize column names by converting them to lowercase and replacing spaces with underscores
cleanSpecies <- clean_names(endangeredSpecies)
# create a numeric population estimate column
# extract the first number from each population estimate
# values such as "unknown" become NA
cleanSpecies <- cleanSpecies %>%
mutate(
population_numeric = parse_number(population_estimate)
)
# save the cleaned dataset as a new CSV file
write_csv(cleanSpecies, here("data", "cleanSpecies.csv"))
# count the number of species recorded in each habitat using a horizontal bar chart
cleanSpecies %>%
ggplot(aes(x = habitat)) +
geom_bar(fill = "darkseagreen") +
labs(
title = "Distribution of Wildlife Species by Habitat",
x = "Habitat",
y = "Number of Species",
caption = "Figure 1. Number of wildlife species recorded in each habitat type. Bar lengths represent the number of observations in the dataset."
) +
coord_flip()+
theme_minimal() +
theme(
# left-align the caption for readability
plot.caption = element_text(
size = 8,
hjust = 0
)
)
# compare the number of species in each conservation category across geographic regions
cleanSpecies %>%
ggplot(aes(x = region, fill = iucn_status)) +
geom_bar() +
labs(
title = "Wildlife Conservation Status Across Regions",
x = "Geographic Region",
y = "Number of Species",
fill = "IUCN Status",
caption = "Figure 2. Species counts by IUCN status across geographic regions. Colors represent conservation categories."
) +
coord_flip() +
theme_minimal() +
theme(
# left-align the caption for readability
plot.caption = element_text(
size = 8,
hjust = 0
)
)
# show the distribution of population estimates in each habitat using a violin plot
cleanSpecies %>%
ggplot(aes(x = habitat,
y = population_numeric,
fill = habitat)) +
geom_violin() +
labs(
title = "Population Estimates Across Habitats",
x = "Habitat",
y = "Approximate Population Estimate",
caption = "Figure 3. Distribution of approximate population estimates across habitat types. Ranges represented by their lower bound."
) +
# use a logarithmic scale to display widely varying estimates
scale_y_log10() +
# angle habitat labels to reduce overlap
theme(
axis.text.x = element_text(
angle = 45,
hjust = 1),
# adjust caption size and alignment
plot.caption = element_text(
size = 8,
hjust = 0
),
# remove the legend
legend.position = "none"
)
The comparisons reveal differences in how wildlife species are represented across habitats and geographic regions. Tropical forests contain the largest number of recorded species in the dataset. The regional comparison shows that Asia has the highest overall species count, with different conservation status categories represented across regions. The violin plot shows that population estimates vary widely within habitats, with some species having much larger estimated populations than others. These comparisons highlight variation in species representation, conservation status, and population estimates. However, the results reflect only the species included in this dataset, and population estimates are approximate because some original values were ranges or upper limits.
CSV Preview. (n.d.). Endangered species IUCN. https://csvpreview.com/data/animals-nature/endangered-species-iucn