LOAD PACKAGES AND FUNCTIONS

Packages

pacman::p_load(tidyverse,extrafont,gridExtra,RColorBrewer)

Set theme

my_color <-"#159858"
my_theme <- function(base_size =5, base_family = "CMU Serif" ){
    theme_bw(base_size = base_size, base_family = base_family) +
        theme(
            panel.grid.major = element_line(color = NA),
            strip.background = element_rect(fill = my_color, color = my_color, size =0.5),
            strip.text = element_text(face = "bold", size = 14, color = "white"))
}
theme_set(my_theme(15))

Function

b.line.plot <- function(df,mapping){
    ggplot(data=df, mapping) +
        geom_line()+geom_point()+
        scale_x_continuous(limits = c(1984, 2017),breaks=seq(1984,2017,1))+
        theme(axis.text.x = element_text(angle=90,size=10))+
        facet_grid(~sp)+scale_color_brewer(palette="Set1")
}

READ DATA

data <- read_csv("Cecropia_indi_all.csv")
# remove plot 17 and 18 ; sp != Indet.
data <- data %>% filter(plot<17&sp!="Indet.")
data$Disturbed[data$Disturbed==1] <- 'Disturbed'
data$Disturbed[data$Disturbed==0] <- 'Non'
str(data)
## Classes 'tbl_df', 'tbl' and 'data.frame':    2344 obs. of  20 variables:
##  $ ID        : chr  "10-1-2001" "11-3-902" "2-1-2019" "2-4-630" ...
##  $ plot      : int  10 11 2 2 4 5 5 5 6 8 ...
##  $ x         : num  -52.9 -52.9 -52.9 -52.9 -52.9 ...
##  $ y         : num  5.26 5.26 5.27 5.27 5.27 ...
##  $ z         : num  18.4 31.6 11.8 21.8 13.8 ...
##  $ slope     : num  21.68 4.57 17.74 8.42 15.38 ...
##  $ Xutm      : num  286528 286249 285112 285245 286015 ...
##  $ Yutm      : num  581784 581237 582784 582673 582866 ...
##  $ sp        : chr  "obtusa" "obtusa" "obtusa" "obtusa" ...
##  $ Mort      : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ Type      : int  6 0 6 6 6 0 0 6 6 0 ...
##  $ mort_year : int  2003 1997 2009 2013 2005 2009 2005 2007 2008 2005 ...
##  $ recru_year: int  1984 1984 1984 1984 1984 1984 1984 1984 1984 1984 ...
##  $ last_year : int  2003 1997 2009 2013 2005 2009 2005 2007 2008 2005 ...
##  $ Age       : int  19 13 25 29 21 25 21 23 24 21 ...
##  $ recru_dbh : num  20.4 12.7 13.2 26.6 23.4 ...
##  $ last_dbh  : num  32.1 13.1 19.9 30.6 25.1 ...
##  $ AGR       : num  0.6199 0.0245 0.2674 0.1372 0.0834 ...
##  $ Disturbed : chr  "Non" "Non" "Non" "Non" ...
##  $ Topo      : chr  "Bas fond" "Plateau" "Pente" "Plateau" ...
##  - attr(*, "spec")=List of 2
##   ..$ cols   :List of 20
##   .. ..$ ID        : list()
##   .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
##   .. ..$ plot      : list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ x         : list()
##   .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
##   .. ..$ y         : list()
##   .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
##   .. ..$ z         : list()
##   .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
##   .. ..$ slope     : list()
##   .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
##   .. ..$ Xutm      : list()
##   .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
##   .. ..$ Yutm      : list()
##   .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
##   .. ..$ sp        : list()
##   .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
##   .. ..$ Mort      : list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ Type      : list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ mort_year : list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ recru_year: list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ last_year : list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ Age       : list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ recru_dbh : list()
##   .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
##   .. ..$ last_dbh  : list()
##   .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
##   .. ..$ AGR       : list()
##   .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
##   .. ..$ Disturbed : list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ Topo      : list()
##   .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
##   ..$ default: list()
##   .. ..- attr(*, "class")= chr  "collector_guess" "collector"
##   ..- attr(*, "class")= chr "col_spec"
data
## # A tibble: 2,344 x 20
##           ID  plot         x        y     z    slope     Xutm     Yutm
##        <chr> <int>     <dbl>    <dbl> <dbl>    <dbl>    <dbl>    <dbl>
##  1 10-1-2001    10 -52.92612 5.260454 18.45 21.67917 286528.2 581783.6
##  2  11-3-902    11 -52.92862 5.255505 31.64  4.57059 286249.3 581237.1
##  3  2-1-2019     2 -52.93892 5.269454 11.76 17.73985 285111.7 582783.5
##  4   2-4-630     2 -52.93772 5.268461 21.79  8.41909 285244.6 582673.2
##  5   4-4-200     4 -52.93078 5.270225 13.80 15.38351 286014.6 582866.0
##  6   5-1-230     5 -52.92977 5.272595 28.26 11.23609 286127.1 583127.7
##  7   5-2-659     5 -52.92818 5.272659 18.27 15.88953 286303.2 583134.2
##  8   5-2-667     5 -52.92826 5.272764 20.07 13.34413 286294.8 583145.9
##  9   6-1-142     6 -52.92699 5.272309 24.66 10.06466 286435.8 583095.2
## 10   8-3-471     8 -52.93079 5.263274 21.98 17.96872 286010.9 582097.1
## # ... with 2,334 more rows, and 12 more variables: sp <chr>, Mort <int>,
## #   Type <int>, mort_year <int>, recru_year <int>, last_year <int>,
## #   Age <int>, recru_dbh <dbl>, last_dbh <dbl>, AGR <dbl>,
## #   Disturbed <chr>, Topo <chr>

TOPOGRAPHY

Recruitment

recru <- data %>% group_by(sp,Topo,recru_year)%>% tally(wt=NULL) %>% 
    mutate(cumsum=cumsum(n))

g1 <- b.line.plot(recru,aes(recru_year,n,group=Topo,color=Topo))
g2 <- b.line.plot(recru,aes(recru_year,cumsum,group=Topo,color=Topo))
grid.arrange(g1,g2,nrow=2)

Death

death <- data %>% filter(Mort==1) %>% group_by(sp,Topo,mort_year)%>% tally(wt=NULL)%>% 
    mutate(cumsum=cumsum(n))
g1 <- b.line.plot(death,aes(mort_year,n,group=Topo,color=Topo))
g2 <- b.line.plot(death,aes(mort_year,cumsum,group=Topo,color=Topo))
grid.arrange(g1,g2,nrow=2)

ZONE DISTURBED

Recruitment

recru <- data %>% group_by(sp,Disturbed,recru_year)%>% tally(wt=NULL) %>% 
    mutate(cumsum=cumsum(n))
g1 <- b.line.plot(recru,aes(recru_year,n,group=Disturbed,color=Disturbed))
g2 <- b.line.plot(recru,aes(recru_year,cumsum,group=Disturbed,color=Disturbed))
grid.arrange(g1,g2,nrow=2)

Death

death <- data %>% filter(Mort==1) %>% group_by(sp,Disturbed,mort_year)%>% tally(wt=NULL) %>% 
    mutate(cumsum=cumsum(n))
g1 <- b.line.plot(death,aes(mort_year,n,group=Disturbed,color=Disturbed))
g2 <- b.line.plot(death,aes(mort_year,cumsum,group=Disturbed,color=Disturbed))
grid.arrange(g1,g2,nrow=2)

TOPOGRAPHY + ZONE DISTURBED

Recruitment

recru <- data %>% group_by(sp,Topo,Disturbed,recru_year)%>% tally(wt=NULL) %>% 
    mutate(cumsum=cumsum(n),habit=paste0(Topo,"_",Disturbed))
g1 <- b.line.plot(recru,aes(recru_year,n,group=habit,color=habit))
g2 <- b.line.plot(recru,aes(recru_year,cumsum,group=habit,color=habit))
grid.arrange(g1,g2,nrow=2)

Death

death <- data %>% filter(Mort==1)%>% group_by(sp,Topo,Disturbed,mort_year)%>% tally(wt=NULL) %>% 
    mutate(cumsum=cumsum(n),habit=paste0(Topo,"_",Disturbed))
g1 <- b.line.plot(death,aes(mort_year,n,group=habit,color=habit))
g2 <- b.line.plot(death,aes(mort_year,cumsum,group=habit,color=habit))
grid.arrange(g1,g2,nrow=2)