Loading Packages

library(tidyverse)
## Warning: package 'ggplot2' was built under R version 4.4.3
## Warning: package 'tidyr' was built under R version 4.4.3
## Warning: package 'readr' was built under R version 4.4.3
## Warning: package 'purrr' was built under R version 4.4.3
## Warning: package 'dplyr' was built under R version 4.4.3
## Warning: package 'lubridate' was built under R version 4.4.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.2.0     ✔ readr     2.2.0
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.5     ✔ tidyr     1.3.2
## ✔ purrr     1.2.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(readxl)

Reading file

# Loading biodiversity dataset from Uppsala site
uppsala <- read_excel("/Users/uwu/Documents/Rstudio/Transect_Data_Set/europe/UPPSALA.xls")
## New names:
## • `voucher` -> `voucher...5`
## • `voucher` -> `voucher...6`
## • `voucher` -> `voucher...7`
## • `voucher` -> `voucher...8`
## • `voucher` -> `voucher...9`
## • `voucher` -> `voucher...10`
## • `voucher` -> `voucher...11`
## • `voucher` -> `voucher...12`
## • `Stemdbh` -> `Stemdbh...15`
## • `Stemdbh` -> `Stemdbh...16`
## • `Stemdbh` -> `Stemdbh...17`
## • `Stemdbh` -> `Stemdbh...18`
## • `Stemdbh` -> `Stemdbh...19`
## • `Stemdbh` -> `Stemdbh...20`
## • `Stemdbh` -> `Stemdbh...21`
## • `Stemdbh` -> `Stemdbh...22`
## • `Stemdbh` -> `Stemdbh...23`
## • `Stemdbh` -> `Stemdbh...24`
## • `Stemdbh` -> `Stemdbh...25`
# Checking column names
names(uppsala)
##  [1] "Line"         "Family"       "Genus"        "Species"      "voucher...5" 
##  [6] "voucher...6"  "voucher...7"  "voucher...8"  "voucher...9"  "voucher...10"
## [11] "voucher...11" "voucher...12" "Liana"        "N(Ind.)"      "Stemdbh...15"
## [16] "Stemdbh...16" "Stemdbh...17" "Stemdbh...18" "Stemdbh...19" "Stemdbh...20"
## [21] "Stemdbh...21" "Stemdbh...22" "Stemdbh...23" "Stemdbh...24" "Stemdbh...25"

Species richness calcuation

# calculating species richness for each transect line
species_richness <- uppsala %>%
  filter(!is.na(Species)) %>% # Removing rows with missing species name
  group_by(Line) %>% # Grouping dataset by transect
  summarise( # counting the number of unique species in each transect
    richness = n_distinct(Species)
  )

# Printing table
print(species_richness)
## # A tibble: 10 × 2
##    Line  richness
##    <chr>    <int>
##  1 1            5
##  2 10           7
##  3 2            5
##  4 3            5
##  5 4            4
##  6 5            5
##  7 6            5
##  8 7            8
##  9 8            6
## 10 9            4

Visualizations - Figure 1. Species richness by transect at the Uppsala site (Europe)

species_richness$Line <- as.numeric(species_richness$Line)

# creating bar graph showing species richness by transect

ggplot(species_richness,
       aes(x = factor(Line),
           y = richness)) +
# for the bars representing richness values
  geom_col(fill = "forestgreen") +
# Adding graph title and axis labels
  labs(
    title = "Species Richness by Transect",
    x = "Transect Line",
    y = "Number of Species"
  ) +
# Applying a black and white theme for a cleaner visual
  theme_bw()