---
title: "TraitsCorrelationMatrix"
author: ""
date: "5/16/2022"
output: html_document
---

```{r}
#read in data
data <- read.csv("BeeCanyonTraitData.csv", header=TRUE)
```

```{r}
#load packages
library(GGally)
library(dplyr)
```

```{r}
#check your data
str(data)
```

```{r}
#examine data frame
bdpairs <- ggpairs(data[-1],upper = list(continuous = wrap('cor',size = 4,col ='black')),
                   lower = list('dot'), columnLabels = strwrap(colnames(data[,-1]))) + theme_bw(base_size = 12)
bdpairs
```

```{r}
#run each trait and fire response separate
#photosynthetic rate
photo.model <- lm(FireResponse ~ Photo2013, data=data)
summary(photo.model)
plot(data$Photo2013, data$FireResponse)
plot(data$Photo2013, data$FireResponse, xlab="Photosynthetic Rate", ylab="Fire Response")
text(data$FireResponse~data$Photo2013, labels=SpeciesCode, data=data, cex=0.5, pos=1)
abline(lm(data$FireResponse~data$Photo2013), col= "red", lwd=2)
```

```{r}
#run each trait and fire response separate
#relative growth rate
rgr.model <- lm(FireResponse ~ RGR2015, data=data)
summary(rgr.model)
plot(data$RGR2015, data$FireResponse)
plot(data$RGR2015, data$FireResponse, xlab="Relative Growth Rate", ylab="Fire Response")
text(data$FireResponse~data$RGR2015, labels=SpeciesCode, data=data, cex=0.5, pos=1)
abline(lm(data$FireResponse~data$RGR2015), col= "red", lwd=2)
```

```{r}
#run each trait and fire response separate
#specific leaf area
sla.model <- lm(FireResponse ~ SLA2015, data=data)
summary(sla.model)
plot(data$SLA2015, data$FireResponse)
plot(data$SLA2015, data$FireResponse, xlab="Specific Leaf Area", ylab="Fire Response")
text(data$FireResponse~data$SLA2015, labels=SpeciesCode, data=data, cex=0.5, pos=1)
abline(lm(data$FireResponse~data$SLA2015), col= "red", lwd=2)
```

```{r}
#run each trait and fire response separate
#percent nitrogen
n.model <- lm(FireResponse ~ N2015, data=data)
summary(n.model)
plot(data$N2015, data$FireResponse)
plot(data$N2015, data$FireResponse, xlab="Percent Nitrogen", ylab="Fire Response")
```

```{r}
#run a perennial matrix
data.perennials <- data %>% filter(SpeciesCode %in% c("ACMGLA", "ARTCAL", "ERIFAS", "SALMEL", "STIPUL"))
perennial.matrix <- ggpairs(data.perennials[-1],upper = list(continuous = wrap('cor',size = 4,col ='black')),
                   lower = list('dot'), columnLabels = strwrap(colnames(data.perennials[,-1]))) + theme_bw(base_size = 12)
perennial.matrix
```

```{r}
#run a annual matrix
data.annuals <- data %>% filter(SpeciesCode %in% c("BRANIG", "BRODIA", "BROMAD", "DEIFAS", "EROCIC", "MALSAX"))
annual.matrix <- ggpairs(data.annuals[-1],upper = list(continuous = wrap('cor',size = 4,col ='black')),
                lower = list('dot'), columnLabels = strwrap(colnames(data.annuals[,-1]))) + theme_bw(base_size = 12)
annual.matrix
```
