About this notebook
This notebook includes R code to reproduce the figures from the publication How do forest fires affect soil greenhouse gas emissions in upland boreal forests? A review accessible through here.
Packages used ggplot2, ggformula, and extrafont. See citation at the end of script.
GitHub repository for the publication using JMP scripts: datainbrief-repo
GitHub repository for this notebook: datainbrief-binder
Figure 2
#Load libraries and pick fonts
library(ggplot2)
library(ggformula)
library("extrafont")
<- "Segoe UI"
myFont windowsFonts(mono = myFont)
#Load data
<- read.table(file = "ghg-fluxes.csv",
data header = TRUE,
dec = ".",
sep = ",")
#Select relevant variables for fig.1
<- c("Rs", "Ageclass","Ageclass100", "Severity1",
myvars "Severity2", "Source", "Region")
<- data[myvars]
newdata
#Make sure factors are factors
$Severity<-factor(newdata$Severity1)
newdata$Severity2<-factor(newdata$Severity2)
newdata$Source<-factor(newdata$Source)
newdata$Region<-factor(newdata$Region)
newdata
#Check and exclude missing data
colSums(is.na(newdata))
## Rs Ageclass Ageclass100 Severity1 Severity2 Source
## 0 0 0 11 0 0
## Region Severity
## 0 11
<- na.exclude(newdata)
data1
#Check means that extrapolate
##We can see that most mean CO2 fluxes after high (H) and low (L) severity
##fires are within a similar range, and H includes a few means that extrapolate that.
dotchart(data1$Rs, group = data1$Severity)
#Omit means that extrapolate (like done the in the paper)
<- subset(data1, Rs < 30)
data2 $ID <- seq.int(nrow(data2))
data2<- data2[ !(data2$ID %in% c(55, 105, 106, 107)), ] data3
#Create labels for graph
$labelsev2 <- factor(data3$Severity2,labels =
data3c("High severity", "Low severity", "Unburned"))
$labelsev <- factor(data3$Severity,labels =
data3c("High severity", "Low severity"))
<- subset(data3, labelsev == "High severity")
dataH <- subset(data3, labelsev == "Low severity")
dataL
#Plot the graph as in fig. 1
<- ggplot() +
p1 geom_jitter(aes(y = Rs,
x = Ageclass100,
col = labelsev2,
shape = labelsev2),
data = data3,
size = 1) +
geom_spline(aes(y = Rs,
x = Ageclass100,
col = labelsev),
data = dataH,
df = 5.5,
alpha = 1,
size = 0.5) +
geom_spline(aes(y = Rs,
x = Ageclass100,
col = labelsev),
data = dataL,
df = 4,
alpha = 1,
size = 0.5) +
labs(x = "Time after fire (years)",
y = (bquote(''*g ~CO[2]~ m^-2~d^-1*''))) +
theme_bw() +
theme(legend.position = c(0.155, 0.91),
legend.text = element_text(size = 10),
legend.title = element_blank(),
legend.key.size = unit(0.5,"line"),
axis.title = element_text(size=12),
axis.text = element_text(size=10)) +
theme(text = element_text(size = 12, family="mono")) +
scale_x_continuous(breaks = seq(0, 100, by = 20)) +
scale_colour_manual(name = "labelsev2",
breaks = c("High severity", "Low severity",
"Unburned"),
values = c("black", "gray",
"#085844")) +
scale_shape_manual(name = "labelsev2",
breaks = c("High severity", "Low severity",
"Unburned"),
values = c(1, 1, 16))
p1