This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
##Need to load the library from previously installed packages or you may need to install some of these packages first.
library(ggplot2)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ lubridate 1.9.4 ✔ tibble 3.3.0
## ✔ purrr 1.1.0 ✔ tidyr 1.3.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(formattable)
library(kableExtra)
##
## Attaching package: 'kableExtra'
##
## The following object is masked from 'package:dplyr':
##
## group_rows
library(allodb)
library(readxl)
#allows direct reading of Excel file formats
setwd("~/Desktop/Hopkins/forested landscapes")
#data <- read_excel(file.choose()) #Allows to choose file with mouse
data <- read_excel("dbhtestforAGB.xlsx")
## New names:
## • `` -> `...10`
get_biomass(
dbh = 50,
genus = "Quercus",
species = "alba",
coords = c(-76.16, 39.68)
)
## [1] 1923.479
data$agb <-
get_biomass(
dbh = data$dbh,
genus = data$genus,
species = data$species,
coords = c(-76.16, 39.68)
)
sum(data$agb) #Add up total biomass
## [1] 23505.41
#Assuming that 50% of wood biomass is carbon, we can also calculate how much carbon is stored in the aboveground portion of the tree, measured in kilograms:
data$Carbon<-round(data$agb/2,1)
#Better to scale to carbon by assuming a 48% carbon content of broadleaved trees in temperate forests (IPCC, 2006).
data$Carbon<-round(data$agb*.48,1)
#For fun let’s calculate carbon dioxide uptake. CO2 (kg) = total carbon (kg) x 3.67
data$CO2e <- round(data$agb*3.67)
sum(data$CO2e)
## [1] 86265
#Fancy way to make a table to export as a graphic
data_show <- data[, 3:11] %>%
head(30)
data_show %>%
kable("html", caption = 'Tree data set with predictions of biomass and carbon in kilograms.') %>%
# kable_styling(position = "center") %>%
kable_styling()
| dbh | genus | species | Family | long | lat | Group ID | …10 | agb |
|---|---|---|---|---|---|---|---|---|
| 14.7 | Pinus | strobus | Pinaceae | -76.60000 | 39.30000 | Wilber | NA | 70.5406810 |
| 82.5 | Fagus | grandifolia | Fagaceae | -76.62420 | 39.32807 | ob, cw, lm, tw | NA | 6158.2985707 |
| 32.5 | Quercus | alba | Fagaceae | -76.62478 | 39.32888 | ob, cw, lm, tw | NA | 744.1320791 |
| 62.0 | Fagus | grandifolia | Fagaceae | -76.62492 | 39.32919 | ob, cw, lm, tw | NA | 3038.5347634 |
| 2.0 | Ilex | opaca | Aquifoliaceae | -76.62472 | 39.32911 | ob, cw, lm, tw | NA | 0.5541136 |
| 20.6 | Liriodendron | tulipifera | Magnoliaceae | -76.62466 | 39.32907 | ob, cw, lm, tw | NA | 192.9447592 |
| 65.0 | Fagus | grandifolia | Fagaceae | -76.62392 | 39.33009 | ES, RA, IN | NA | 3415.1731825 |
| 19.3 | Quercus | rubra | Fagaceae | -76.62400 | 39.33005 | ES, RA, IN | NA | 236.2479569 |
| 30.5 | Juglans | nigra | Juglandaceae | 76.62397 | 39.33000 | ES, RA, IN | NA | 527.1669908 |
| 9.8 | Ilex | opaca | Aquifoliaceae | -76.62390 | 39.33000 | ES, RA, IN | NA | 28.4374556 |
| 9.6 | Liriodendron | tulipifera | Magnoliaceae | -76.62406 | 39.33001 | ES, RA, IN | NA | 31.5801894 |
| 49.8 | Fagus | grandifolia | Fagaceae | -76.62000 | 39.33000 | SM, MJ, AJ | NA | 1767.4004581 |
| 94.1 | Liriodendron | tulipifera | Magnoliaceae | -76.62000 | 39.33000 | SM, MJ, AJ | NA | 7067.1644075 |
| 4.4 | Fraxinus | americana | Oleaceae | -76.62000 | 39.33000 | SM, MJ, AJ | NA | 6.1505114 |
| 21.0 | Ilex | opaca | Aquifoliaceae | -76.62000 | 39.33000 | SM, MJ, AJ | 12.7+8.3 | 187.9685623 |
| 10.7 | Magnolia | tripetala | Magnoliaceae | -76.62000 | 39.33000 | SM, MJ, AJ | NA | 33.1196332 |