-
Notifications
You must be signed in to change notification settings - Fork 0
/
FIA_alternate_disturbance_analysis.Rmd
79 lines (63 loc) · 2.49 KB
/
FIA_alternate_disturbance_analysis.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---
title: "FIA_alternate_tsd"
author: "Katie Nigro"
date: "`r Sys.Date()`"
output: html_document
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
dist_seeds_joined_alt <- dist_seeds_joined %>%
filter(!(Agent == "insect.disease" & !source=="tree_table" & dist_year == MEASYEAR)) %>%
mutate(tsd=MEASYEAR - dist_year) %>%
filter(Agent %in% c("fire","insect.disease","none"))
ggplot(dist_seeds_joined_alt %>% filter(!source=="tree_table"))+
geom_histogram(aes(x=tsd))+
facet_wrap(~Agent, scales="free")
ggplot(dist_tsd %>% filter(tsd>0))+
geom_boxplot(aes(x=Agent, y=tsd))
##time since disturbance for insect/disease was much shorter on average than for fire.
```
```{r, echo=FALSE}
##create function that appends climate data to each species/lifestage/disturbance
#' merge_sp_dist_env
#'
#' @param joined_df dataframe with disturbance and species data joined. Either species.sum.long or dist_seeds_joined
#' @param sp_code code for desired species. Can be found in FIA user guide.
#' @param agent_name name of the desired disturbance. Either fire, insect.disease, harvest, other or none.
#' @param env_vars environmental variables dataframe. Called env_vars here.
#'
#' @return dataframe with environmental variables associated with each plot for a desired species/lifestage/disturbance combination
#' @export
#'
#' @examples
merge_sp_dist_env <- function(joined_df, sp_code, agent_name, env_vars) { sp_dist_env <- joined_df %>%
filter(SPCD == sp_code &
Agent == agent_name) %>%
dplyr::select(SPCD, PLT_CN, Agent, dist_year, source) %>%
left_join(env_vars, by = "PLT_CN")
return(sp_dist_env)
}
#FIA codes for all desired species (n=16) and disturbances (n=3)
sp_codes <- as.character(unique(sample_seeds_over60$SPCD))
dist_names <- c("fire","insect.disease","none")
#put environmental data for each species/disturbance combination in a dataframe within a list for adults
adult_data <- list()
for(i in 1:length(sp_codes)){
for(j in 1:length(dist_names)){
df <- merge_sp_dist_env(species.sum.long, sp_codes[i], dist_names[j], env_vars)
adult_data[[paste(sp_codes[i],"_",dist_names[j],"_cvars",sep="")]]<- df
}
}
#list for seedlings
seedling_data <- list()
for(i in 1:length(sp_codes)){
for(j in 1:length(dist_names)){
df <- merge_sp_dist_env(dist_seeds_joined, sp_codes[i], dist_names[j], env_vars)
seedling_data[[paste(sp_codes[i],"_",dist_names[j],"_cvars",sep="")]]<- df
}
}
```