Packages I used and the reading in the two sites I chose which were Cary Arboretum, U.S.A., New York and Heuston Woods (Beech/Maple), U.S.A., Ohio. I tried to load the BiodiveristyR package but it would only load somethings and then stop and crash R studio.
library(readxl)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.2 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── 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(BiodiversityR) #does not want to load
## Loading required package: tcltk
## Loading required package: vegan
## Loading required package: permute
## Loading required package: lattice
## This is vegan 2.6-4
## BiodiversityR 2.16-1: Use command BiodiversityRGUI() to launch the Graphical User Interface;
## to see changes use BiodiversityRGUI(changeLog=TRUE, backward.compatibility.messages=TRUE)
cary<-read_xls("Transect_Data_Set/temp.namerica/CARY.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`
hbm<-read_xls("Transect_Data_Set/temp.namerica/HEUSTOBM.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`
Cleaning the site data for my two locations such as getting rid of all the voucher columns and pivoting the data on stem DBH.
ccary<- cary %>%
select(-voucher...5,-voucher...6,-voucher...7,-voucher...8,-voucher...9, #gets rid of columns, pivots data
-voucher...10,-voucher...11,-voucher...12,-Liana, -"N(Ind.)") %>% #and gets rid of NA values
pivot_longer(cols = starts_with("Stemdbh"),
values_to = "Stemdbh") %>%
filter(!is.na(Stemdbh)) %>%
select(-name)
chbm<- hbm %>%
select(-voucher...5,-voucher...6,-voucher...7,-voucher...8,-voucher...9,
-voucher...10,-voucher...11,-voucher...12,-Liana, -"N(Ind.)") %>%
pivot_longer(cols = starts_with("Stemdbh"),
values_to = "Stemdbh") %>%
filter(!is.na(Stemdbh)) %>%
select(-name)
These are the functions I created in order to create graphs of the stem DBH of individuals in each line/transect.
seplines<-function(x, num){ #function to separate df by lines in order to graph them by lines
filter(x, Line== num)
}
dbhgraph<-function(x,name){ #function to graph the dbh of individuals and by species
ggplot(x, aes(Species, Stemdbh, fill = Species)) +
geom_bar(stat = "identity", position = "dodge2") +
labs(x = "Species", y = "Stemdbh, cm", title= name) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
}
# EXAMPLE ggplot(hbm5, aes(Species, Stemdbh, fill = Species)) +
# geom_bar(stat = "identity", position = "dodge2") +
# labs(x = "Species", y = "Stemdbh", title="Stem DBH per Species, Line 5")
hbm1<-seplines(chbm,1) #HBM Site
hbm2<-seplines(chbm,2)
hbm3<-seplines(chbm,3)
hbm4<-seplines(chbm,4)
hbm5<-seplines(chbm,5)
hbm6<-seplines(chbm,6)
hbm7<-seplines(chbm,7)
hbm8<-seplines(chbm,8)
hbm9<-seplines(chbm,9)
hbm10<-seplines(chbm,10)
dbhgraph(hbm1, "Stem DBH per Species, Line 1")
dbhgraph(hbm2, "Stem DBH per Species, Line 2")
dbhgraph(hbm3, "Stem DBH per Species, Line 3")
dbhgraph(hbm4, "Stem DBH per Species, Line 4")
dbhgraph(hbm5, "Stem DBH per Species, Line 5")
dbhgraph(hbm6, "Stem DBH per Species, Line 6")
dbhgraph(hbm7, "Stem DBH per Species, Line 7")
dbhgraph(hbm8, "Stem DBH per Species, Line 8")
dbhgraph(hbm9, "Stem DBH per Species, Line 9")
dbhgraph(hbm10, "Stem DBH per Species, Line 10")
cary1<-seplines(ccary,1) #Cary Site
cary2<-seplines(ccary,2)
cary3<-seplines(ccary,3)
cary4<-seplines(ccary,4)
cary5<-seplines(ccary,5)
cary6<-seplines(ccary,6)
cary7<-seplines(ccary,7)
cary8<-seplines(ccary,8)
cary9<-seplines(ccary,9)
cary10<-seplines(ccary,10)
dbhgraph(cary1, "Stem DBH per Species, Line 1")
dbhgraph(cary2, "Stem DBH per Species, Line 2")
dbhgraph(cary3, "Stem DBH per Species, Line 3")
dbhgraph(cary4, "Stem DBH per Species, Line 4")
dbhgraph(cary5, "Stem DBH per Species, Line 5")
dbhgraph(cary6, "Stem DBH per Species, Line 6")
dbhgraph(cary7, "Stem DBH per Species, Line 7")
dbhgraph(cary8, "Stem DBH per Species, Line 8")
dbhgraph(cary9, "Stem DBH per Species, Line 9")
dbhgraph(cary10, "Stem DBH per Species, Line 10")