Plots of DBH by Species per Transect

# Create boxplots of DBH by species, faceted by site
ggplot(biodiv_data, aes(x = reorder(species, dbh, median), y = dbh)) +
  geom_boxplot(outlier.size = 0.8, alpha = 0.7, fill = "#69b3a2") +
  facet_wrap(~site, scales = "free_y") +  # separate plots by site
  coord_flip() +  # rotate for readability
  theme_minimal() +
  labs(
    title = "DBH Distribution by Species (All Species, Faceted by Site)",
    x = "Species",
    y = "DBH (cm)"
  ) +
  theme(
    strip.text = element_text(size = 12, face = "bold"),
    axis.text.y = element_text(size = 8),
    axis.text.x = element_text(size = 10),
    plot.title = element_text(face = "bold", hjust = 0.5)
  )

Summarized DBH Comparison by Site

# Summary plot of DBH by site
ggplot(biodiv_data, aes(x = site, y = dbh, fill = site)) +
  geom_boxplot(alpha = 0.7) +
  theme_minimal() +
  labs(
    title = "Overall DBH Distribution by Site",
    x = "Site",
    y = "DBH (cm)"
  ) +
  theme(
    plot.title = element_text(face = "bold", hjust = 0.5),
    legend.position = "none"
  )

Biodiversity Index Table per Transect

# Create species abundance matrix by transect
abundance_matrix <- biodiv_data %>%
  count(site, transect, species) %>%
  mutate(transect_id = paste(site, transect, sep = "_")) %>%
  select(transect_id, species, n) %>%
  pivot_wider(names_from = species, values_from = n, values_fill = 0) %>%
  tibble::column_to_rownames("transect_id")

# Calculate biodiversity indices for each transect
shannon <- diversity(abundance_matrix, index = "shannon")
simpson <- diversity(abundance_matrix, index = "simpson")
inv_simpson <- diversity(abundance_matrix, index = "invsimpson")
richness <- specnumber(abundance_matrix)  # species richness (S)
shannon_E <- shannon / log(richness)      # Shannon evenness
simpson_E <- inv_simpson / richness       # Simpson evenness

# Combine results into a single data frame
biodiv_table <- data.frame(
  Shannon = round(shannon, 3),
  Simpson = round(simpson, 3),
  Inverse_Simpson = round(inv_simpson, 3),
  Richness = richness,
  Shannon_Evenness = round(shannon_E, 3),
  Simpson_Evenness = round(simpson_E, 3)
)

# Move transect names into a column
biodiv_table <- tibble::rownames_to_column(biodiv_table, var = "transect")

# Display biodiversity table
knitr::kable(biodiv_table, caption = "Biodiversity Indices by Transect")
Biodiversity Indices by Transect
transect Shannon Simpson Inverse_Simpson Richness Shannon_Evenness Simpson_Evenness
Belinga_1 3.308 0.958 24.045 31 0.963 0.776
Belinga_2 2.824 0.916 11.904 22 0.914 0.541
Belinga_3 3.239 0.946 18.677 31 0.943 0.602
Belinga_4 2.917 0.936 15.680 21 0.958 0.747
Belinga_5 3.241 0.950 19.962 31 0.944 0.644
Belinga_6 0.000 0.000 1.000 1 NaN 1.000
Mudumalai_1 1.581 0.758 4.129 6 0.882 0.688
Mudumalai_2 1.668 0.765 4.261 7 0.857 0.609
Mudumalai_3 0.868 0.500 2.000 3 0.790 0.667
Mudumalai_4 1.255 0.688 3.200 4 0.906 0.800
Mudumalai_5 0.562 0.375 1.600 2 0.811 0.800
Mudumalai_6 0.900 0.531 2.133 3 0.819 0.711
Mudumalai_7 1.242 0.667 3.000 4 0.896 0.750
Mudumalai_8 1.004 0.612 2.579 3 0.914 0.860
Mudumalai_9 0.950 0.560 2.273 3 0.865 0.758
Mudumalai_10 1.733 0.812 5.333 6 0.967 0.889

Site-Level Summary Table

# Extract site name from transect ID
biodiv_table <- biodiv_table %>%
  mutate(site = sub("_.*", "", transect))

# Calculate average indices by site
site_summary <- biodiv_table %>%
  group_by(site) %>%
  summarise(across(where(is.numeric), ~mean(.x, na.rm = TRUE)), .groups = "drop") %>%
  mutate(across(where(is.numeric), ~round(.x, 3)))

# Display site-level summary table
knitr::kable(site_summary, caption = "Average Biodiversity Indices by Site")
Average Biodiversity Indices by Site
site Shannon Simpson Inverse_Simpson Richness Shannon_Evenness Simpson_Evenness
Belinga 2.588 0.784 15.211 22.833 0.944 0.718
Mudumalai 1.176 0.627 3.051 4.100 0.871 0.753

biodiversity vs size plot

# Separate site and transect number in biodiv_table
biodiv_table <- biodiv_table %>%
  separate(transect, into = c("site", "transect"), sep = "_") %>%
  mutate(transect = as.numeric(transect))

# Calculate mean DBH per transect from the raw data
mean_dbh_by_transect <- biodiv_data %>%
  group_by(site, transect) %>%
  summarise(mean_dbh = mean(dbh, na.rm = TRUE), .groups = "drop")

# Join biodiversity metrics with DBH summary
biodiv_size_compare <- left_join(biodiv_table, mean_dbh_by_transect, by = c("site", "transect"))

# Plot Richness vs Mean DBH
ggplot(biodiv_size_compare, aes(x = Richness, y = mean_dbh, color = site)) +
  geom_point(size = 3, alpha = 0.8) +
  geom_smooth(method = "lm", se = FALSE, linetype = "dashed") +
  theme_minimal() +
  labs(
    title = "Relationship Between Species Richness and Mean DBH by Transect",
    x = "Species Richness (S)",
    y = "Mean DBH (cm)",
    color = "Site"
  ) +
  theme(
    plot.title = element_text(face = "bold", hjust = 0.5),
    legend.position = "top"
  )
## `geom_smooth()` using formula = 'y ~ x'

Visual Comparison of Biodiversity Indices Between Sites

site_summary_long <- site_summary %>%
  pivot_longer(cols = c(Shannon, Simpson, Inverse_Simpson, Richness, Shannon_Evenness, Simpson_Evenness),
               names_to = "Index",
               values_to = "Value")

# Plot biodiversity metrics by site
ggplot(site_summary_long, aes(x = Index, y = Value, fill = site)) +
  geom_bar(stat = "identity", position = position_dodge(width = 0.7)) +
  theme_minimal() +
  labs(
    title = "Biodiversity Indices Compared by Site",
    x = "Index",
    y = "Value",
    fill = "Site"
  ) +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1),
    plot.title = element_text(face = "bold", hjust = 0.5)
  )