Skip to content

Commit

Permalink
Merge pull request #3 from ekearsle/master
Browse files Browse the repository at this point in the history
Revisions
  • Loading branch information
ekearsle authored Dec 18, 2023
2 parents 86091b0 + ed33cb0 commit dbc658f
Show file tree
Hide file tree
Showing 84 changed files with 3,122 additions and 120 deletions.
Empty file modified .Rbuildignore
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified DESCRIPTION
100644 → 100755
Empty file.
Empty file modified NAMESPACE
100644 → 100755
Empty file.
189 changes: 189 additions & 0 deletions R/Pierlot_standlevel_phen_plotlevel.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
#' plot-level annual phenological signal
#' species-specific annual signals are weighted by their basal area at the plot level
#'
#' @param data junglerhythms data file
#' @param census_plot yangambi census data at plot level
#' @param total_basal_area_plot total basal area of a plot
#' @param species_name list of species
#' @param pheno only one phenophase
#' @param minimum_siteyears species not included if fewer observation-years overall (across all individuals)
#' @export
#' @return dataframe


standlevel_phen_plotlevel <- function(
data = data,
census_plot = census_plot,
total_basal_area_plot = total_basal_area_plot,
species_list_dorm = dorm_sp1,
species_list_turn = turn_sp1,
minimum_siteyears = minimum_siteyears
){


#-----------------------------------------------------------------------
#-- each phenophase is done seperately
#-- because different species can be sourced per phenophase
#-- based on group classifications
#-----------------------------------------------------------------------

#-----------------------------------------------------------------------
#------------ Leaf turnover -------------------------------------------
#-----------------------------------------------------------------------
if(!is_empty(species_list_turn)){
timelines_turn <- data %>%
filter(phenophase == "leaf_turnover",
species_full %in% species_list_turn,
!is.na(value))
# for each species, get summaries of each week (makes full year per species)
data_LT <- timelines_turn %>%
group_by(species_full, week) %>%
dplyr::summarise(mean_week = mean(value),
total_week = length(value))

# filter out species with too few total observation years across individuals
# to have a meaningfull average year (set by minimum_siteyears)
data_LT <- data_LT %>%
filter(total_week >= minimum_siteyears)

# add species-level basal area (across the 5-ha plots)
data_LT_plot <- inner_join(data_LT, census_plot, by = c("species_full"))


final_LT_plot <- data_LT_plot %>%
group_by(Plot, week) %>%
dplyr::summarise(ss = sum(mean_week*basal_area_plot, na.rm = TRUE))
final_LT_plot <- inner_join(final_LT_plot, total_basal_area_plot, by = c("Plot"))
final_LT_plot <- final_LT_plot %>%
mutate(ss_turn = ss/total_basal_area_plot*100)
final_LT_plot <- final_LT_plot %>%
dplyr::select(Plot, week, ss_turn)
} else {
final_LT_plot <- data.frame(Plot = rep(c("Inventory 20","Inventory 21","Inventory 23"),48),
week = rep(c(1:48),2),
ss_turn = NA)
}
#-----------------------------------------------------------------------

#-----------------------------------------------------------------------
#------------ Leaf dormancy -------------------------------------------
#-----------------------------------------------------------------------
if(!is_empty(species_list_dorm)){
timelines_dorm <- data %>%
filter(phenophase == "leaf_dormancy",
species_full %in% species_list_dorm,
!is.na(value))

data_LD <- timelines_dorm %>%
group_by(species_full, week) %>%
dplyr::summarise(mean_week = mean(value),
total_week = length(value))
data_LD <- data_LD %>%
filter(total_week >= minimum_siteyears)

data_LD_plot <- inner_join(data_LD, census_plot, by = c("species_full"))

final_LD_plot <- data_LD_plot %>%
group_by(Plot, week) %>%
dplyr::summarise(ss = sum(mean_week*basal_area_plot, na.rm = TRUE))
final_LD_plot <- inner_join(final_LD_plot, total_basal_area_plot, by = c("Plot"))
final_LD_plot <- final_LD_plot %>%
mutate(ss_dorm = ss/total_basal_area_plot*100)
final_LD_plot <- final_LD_plot %>%
dplyr::select(Plot, week, ss_dorm)
} else {
final_LD_plot <- data.frame(Plot = rep(c("Inventory 20","Inventory 21","Inventory 23"),48),
week = rep(c(1:48),2),
ss_dorm = NA)
}
#-----------------------------------------------------------------------


# #-----------------------------------------------------------------------
# #------------ Leaf flushing -------------------------------------------
# #-----------------------------------------------------------------------
# if(!is_empty(species_list_dorm)) {
# #------
# # onset of flushing is first calculated as first week end of dormancy events
# # full timeline for flushing is first created for each individual
# #------
# # just to avoid confusion, work with new name
# timelines_flush <- timelines_dorm
# # new column 'flushing_date' to merge with later on
# timelines_flush$flushing_date <- paste(timelines_flush$year, timelines_flush$week, sep = "-")
#
# # function event_length gets
# # for each individual of the requested species
# # start/end year&week of each event
# flushing_timing <- event_length(data = timelines_flush,
# species_name = species_list_dorm,
# pheno = "leaf_dormancy")
# # individuals without events give NA in event_length, so remove
# flushing_timing <- flushing_timing %>%
# filter(!is.na(year_start))
#
# # date of onset flushing = week after end dormancy event
# flushing_timing$flushing_date <- paste(flushing_timing$year_end, flushing_timing$week_end +1, sep = "-")
#
# flushing_timing <- flushing_timing %>%
# select(species_full,
# id,
# flushing_date)
# flushing_timing$flushing_value <- 1
#
# # merge using flushing_date for each id/species
# # flushing_value is
# data_flush <- merge(timelines_flush, flushing_timing, by = c("species_full","id","flushing_date"), all.x = TRUE)
# data_flush$flushing_value <- ifelse(is.na(data_flush$flushing_value),"0", data_flush$flushing_value)
# # if value for dormancy was NA, year was not observed (full timelines were needed for using 'event_length')
# # so remove year for flushing
# data_flush$flushing_value <- ifelse(is.na(data_flush$value),NA, data_flush$flushing_value)
# data_flush$flushing_value <- as.numeric(data_flush$flushing_value)
#
# #------
# ## now continue the same as done for turnover and dormancy
# #------
# data_flush <- data_flush %>%
# group_by(species_full, week) %>%
# dplyr::summarise(mean_week = mean(flushing_value, na.rm = TRUE),
# total_week = length(flushing_value))
#
# data_flush <- data_flush %>%
# filter(total_week >= minimum_siteyears)
#
# data_flush_plot <- inner_join(data_flush, census_plot, by = c("species_full"))
#
# final_flush_plot <- data_flush_plot %>%
# group_by(Plot, week) %>%
# dplyr::summarise(ss = sum(mean_week*basal_area_plot, na.rm = TRUE))
# final_flush_plot <- inner_join(final_flush_plot, total_basal_area_plot, by = c("Plot"))
# final_flush_plot <- final_flush_plot %>%
# mutate(ss_flush = ss/total_basal_area_plot*100)
# final_flush_plot <- final_flush_plot %>%
# dplyr::select(Plot, week, ss_flush)
# } else {
# final_flush_plot <- data.frame(Plot = rep(c("Inventory 20","Inventory 23"),48),
# week = rep(c(1:48),2),
# ss_flush = NA)
# }
# #-----------------------------------------------------------------------

#-----------------------------------------------------------------------
#------ output dataframe ---------------------------------------------
#-----------------------------------------------------------------------
# # add full_range to make sure all plots are included, even if a species is not present in the plot
# combined <- data.frame(Plot = rep(c("Inventory 20","Inventory 23"),48),
# week = rep(c(1:48),2),
# full_range = NA)
# combined <- merge(combined, final_LT_plot, by = c("Plot","week"), all.x = TRUE)
# combined <- merge(combined, final_LD_plot, by = c("Plot","week"), all.x = TRUE)
# combined <- merge(combined, final_flush_plot, by = c("Plot","week"), all.x = TRUE)
# # both dormancy and turnover represent main period of senescence
# combined$ss_senescence <- combined$ss_turn + combined$ss_dorm
# combined <- combined %>%
# dplyr::select(!full_range)

combined <- left_join(final_LD_plot,final_LT_plot)

return(combined)
}
Empty file modified R/bounding_box.R
100644 → 100755
Empty file.
103 changes: 68 additions & 35 deletions R/circular_linear_plots.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
#'
#' @param data junglerhythms data file
#' @param species_name list of species
#' @param leg_gradient color gradient of the circular plots can be adapted
#' @param leg_position legend position (might need to change depending on how many species called)
#' @param title_name title of the plot
#' @export
#' @return ggplot object

library(ggnewscale)

circular_linear_plot <- function(
data = data,
species_name = "Millettia laurentii",
leg_gradient = c(0,0.2,1),
leg_pos = c(1,0.1),
leg_pos = c(1,0.2),
title_name = "(a) evergreen"
){

Expand Down Expand Up @@ -42,6 +42,12 @@ circular_linear_plot <- function(
data_subset_circ$pos[data_subset_circ$phenophase == "leaf_turnover"] <- 1.5
data_subset_circ <- na.omit(data_subset_circ)

# separate dormancy and turnover, to get different scale colors in the fig
data_subset_circ_turn <- data_subset_circ %>%
filter(phenophase %in% 'leaf_turnover')
data_subset_circ_dorm <- data_subset_circ %>%
filter(phenophase %in% 'leaf_dormancy')

#------------------------------------------------------------------------
# data leaf dormancy - linear plots
#------------------------------------------------------------------------
Expand Down Expand Up @@ -84,26 +90,37 @@ circular_linear_plot <- function(
#------------------------------------------------------------------------
# circular plot
#------------------------------------------------------------------------
p_circ <- ggplot(data = data_subset_circ,
aes(
x = week,
xend = week + 1,
y = pos,
yend = pos,
colour = percent_value
)) +
scale_colour_distiller(palette = "YlOrBr",
direction = 1,
name = "mean annual \n% individuals\nwith events",
values = leg_gradient) +
p_circ <- ggplot() +
annotate("rect", xmin = 1, xmax = 9, ymin = 0, ymax = 2.4, alpha = .2) + #jan - feb
annotate("rect", xmin = 21, xmax = 29, ymin = 0, ymax = 2.4, alpha = .2) + # jun-jul
annotate("rect", xmin = 45, xmax = 49, ymin = 0, ymax = 2.4, alpha = .2) + # dec
annotate("text", x = 1, y = 0.8, label = "LD", col = "grey50") +
annotate("text", x = 25, y = 0.8, label = "SD", col = "grey50") +
annotate("text", x = 37, y = 0.8, label = "LW", col = "grey50") +
annotate("text", x = 13, y = 0.8, label = "SW", col = "grey50") +
geom_segment(size = 4) +
annotate("text", x = 1, y = 0.8, label = "LD", col = "grey50", size = 3.5) +
annotate("text", x = 25, y = 0.8, label = "SD", col = "grey50", size = 3.5) +
annotate("text", x = 37, y = 0.8, label = "LW", col = "grey50", size = 3.5) +
annotate("text", x = 13, y = 0.8, label = "SW", col = "grey50", size = 3.5) +
geom_segment(data = data_subset_circ_dorm,
aes(
x = week,
xend = week + 1,
y = pos,
yend = pos,
colour = percent_value
),
size = 4) +
scale_colour_gradientn(colours = c("#ffffcc", "#DFC27D" ,"#BF812D", "#8C510A", "#543005",'#662506'),
name = "Senescence:\nmean annual \n% individuals\nwith events") +
new_scale_color() +
geom_segment(data = data_subset_circ_turn,
aes(
x = week,
xend = week + 1,
y = pos,
yend = pos,
colour = percent_value
),
size = 4) +
scale_colour_gradientn(colours = c("#ffffcc", "#66c2a4", "#41ae76", "#238b45", "#006d2c", "#00441b"),
name = "Turnover:\nmean annual \n% individuals\nwith events") +
scale_x_continuous(limits = c(1,49),
breaks = seq(1,48,4),
labels = month.abb) +
Expand Down Expand Up @@ -171,8 +188,7 @@ circular_linear_plot <- function(
circular_plot <- function(
data = data,
species_name = "Millettia laurentii",
leg_gradient = c(0,0.2,1),
leg_pos = c(1,0.1),
leg_pos = c(1,0.2),
title_name = "(a) evergreen"
){
#------------------------------------------------------------------------
Expand All @@ -197,29 +213,46 @@ circular_plot <- function(
data_subset_circ$pos[data_subset_circ$phenophase == "leaf_turnover"] <- 1.5
data_subset_circ <- na.omit(data_subset_circ)

# separate dormancy and turnover, to get different scale colors in the fig
data_subset_circ_turn <- data_subset_circ %>%
filter(phenophase %in% 'leaf_turnover')
data_subset_circ_dorm <- data_subset_circ %>%
filter(phenophase %in% 'leaf_dormancy')

#------------------------------------------------------------------------
# circular plot
#------------------------------------------------------------------------
p_circ <- ggplot(data = data_subset_circ,
aes(
x = week,
xend = week + 1,
y = pos,
yend = pos,
colour = percent_value
)) +
scale_colour_distiller(palette = "YlOrBr",
direction = 1,
name = "mean annual \n% individuals\nwith events",
values = leg_gradient) +
p_circ <- ggplot() +
annotate("rect", xmin = 1, xmax = 9, ymin = 0, ymax = 2.4, alpha = .2) + #jan - feb
annotate("rect", xmin = 21, xmax = 29, ymin = 0, ymax = 2.4, alpha = .2) + # jun-jul
annotate("rect", xmin = 45, xmax = 49, ymin = 0, ymax = 2.4, alpha = .2) + # dec
annotate("text", x = 1, y = 0.8, label = "LD", col = "grey50", size = 3.5) +
annotate("text", x = 25, y = 0.8, label = "SD", col = "grey50", size = 3.5) +
annotate("text", x = 37, y = 0.8, label = "LW", col = "grey50", size = 3.5) +
annotate("text", x = 13, y = 0.8, label = "SW", col = "grey50", size = 3.5) +
geom_segment(size = 4) +
geom_segment(data = data_subset_circ_dorm,
aes(
x = week,
xend = week + 1,
y = pos,
yend = pos,
colour = percent_value
),
size = 4) +
scale_colour_gradientn(colours = c("#ffffcc", "#DFC27D" ,"#BF812D", "#8C510A", "#543005",'#662506'),
name = "Senescence:\nmean annual \n% individuals\nwith events") +
new_scale_color() +
geom_segment(data = data_subset_circ_turn,
aes(
x = week,
xend = week + 1,
y = pos,
yend = pos,
colour = percent_value
),
size = 4) +
scale_colour_gradientn(colours = c("#ffffcc", "#66c2a4", "#41ae76", "#238b45", "#006d2c", "#00441b"),
name = "Turnover:\nmean annual \n% individuals\nwith events") +
scale_x_continuous(limits = c(1,49),
breaks = seq(1,48,4),
labels = month.abb) +
Expand Down
Empty file modified R/climate_ccf_function.R
100644 → 100755
Empty file.
Empty file modified R/consec_years.R
100644 → 100755
Empty file.
Empty file modified R/event_length.R
100644 → 100755
Empty file.
Empty file modified R/extract_annotations.R
100644 → 100755
Empty file.
Empty file modified R/format_zoo_data.R
100644 → 100755
Empty file.
Empty file modified R/fourier_function_species_level.R
100644 → 100755
Empty file.
Empty file modified R/geometry_functions.R
100644 → 100755
Empty file.
Empty file modified R/line_sections.R
100644 → 100755
Empty file.
Empty file modified R/luki_circular_linear.R
100644 → 100755
Empty file.
Empty file modified R/plot_observations.R
100644 → 100755
Empty file.
Empty file modified R/plot_weekly_annotations.R
100644 → 100755
Empty file.
Empty file modified R/row_locations.R
100644 → 100755
Empty file.
Loading

0 comments on commit dbc658f

Please sign in to comment.