##Just Run This Chunk

require(readxl)
## Loading required package: readxl
require(ggplot2)
## Loading required package: ggplot2
require(plotly)
## Loading required package: plotly
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
require(emmeans)
## Loading required package: emmeans
require(multcomp)
## Loading required package: multcomp
## Loading required package: mvtnorm
## Loading required package: survival
## Loading required package: TH.data
## Loading required package: MASS
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:plotly':
## 
##     select
## 
## Attaching package: 'TH.data'
## The following object is masked from 'package:MASS':
## 
##     geyser
require(tidyverse)
## Loading required package: tidyverse
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v tibble  3.1.4     v dplyr   1.0.7
## v tidyr   1.1.4     v stringr 1.4.0
## v readr   2.0.2     v forcats 0.5.1
## v purrr   0.3.4
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks plotly::filter(), stats::filter()
## x dplyr::lag()    masks stats::lag()
## x dplyr::select() masks MASS::select(), plotly::select()
require(ggpubr)
## Loading required package: ggpubr
require(rstatix)
## Loading required package: rstatix
## 
## Attaching package: 'rstatix'
## The following object is masked from 'package:MASS':
## 
##     select
## The following object is masked from 'package:stats':
## 
##     filter
require(lmerTest)
## Loading required package: lmerTest
## Loading required package: lme4
## Loading required package: Matrix
## 
## Attaching package: 'Matrix'
## The following objects are masked from 'package:tidyr':
## 
##     expand, pack, unpack
## 
## Attaching package: 'lmerTest'
## The following object is masked from 'package:lme4':
## 
##     lmer
## The following object is masked from 'package:stats':
## 
##     step
require(Rmisc)
## Loading required package: Rmisc
## Loading required package: lattice
## Loading required package: plyr
## ------------------------------------------------------------------------------
## You have loaded plyr after dplyr - this is likely to cause problems.
## If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
## library(plyr); library(dplyr)
## ------------------------------------------------------------------------------
## 
## Attaching package: 'plyr'
## The following objects are masked from 'package:rstatix':
## 
##     desc, mutate
## The following object is masked from 'package:ggpubr':
## 
##     mutate
## The following objects are masked from 'package:dplyr':
## 
##     arrange, count, desc, failwith, id, mutate, rename, summarise,
##     summarize
## The following object is masked from 'package:purrr':
## 
##     compact
## The following objects are masked from 'package:plotly':
## 
##     arrange, mutate, rename, summarise
LeafLength = read_excel("C:/Users/diana/Downloads/YDRAY-LeafLength.xlsx")
LeafLength$Temp_C02=paste(LeafLength$Temp,"_and_",LeafLength$CO2,sep="")
LeafLength$id=as.factor(paste(LeafLength$Cab,"_",LeafLength$Obs,sep=""))
LeafLength$Genotype=as.factor(LeafLength$Genotype)

##Time Series Plot by Temp-CO2 Treatment

gd = summarySE(LeafLength, measurevar="LeafL", groupvars=c("Temp_C02","Time","Genotype"))
g1=ggplot(gd,aes(x=Time,y=LeafL,color=Temp_C02, group =Temp_C02))+ geom_line(data=gd)+geom_point(data=gd, size = 2)+ facet_grid(~Genotype)+theme_bw()+
  labs(title = "Leaf Length",
       x = "Time in days",
       y = "Length in cm")
g1

Análisis: En el genotipo PA107 las variables de temperatura y CO2 no representan una gran variación en cuanto al crecimiento de la hoja. En SCA6 se evidencia que el crecimiento depende de las variables de rango de temperatura y CO2, en 60 días las hojas que se encontraban de 31 y 22 a 700 de concentración de CO2 tiene medidas mayores a 30cm, mientras que al mismo tiempo (60 días) las hojas que estaban expuestas de 36 a 27 a 700 de concentración de CO2 tiene un crecimiento de 18cm. Esto indica que en el rango de 31 y 22 a 700 de concentración de CO2 es más eficiete para la obtención de un crecimiento mayor en la parte foliar de las hojas.

##Anova de Medidas Repetidas

LeafLength$Time=as.factor(LeafLength$Time)
LeafLength$Temp=as.factor(LeafLength$Temp)
LeafLength$CO2=as.factor(LeafLength$CO2)

anova=aov(LeafL~Temp*CO2*Genotype+Time+Error(id/Genotype/Time),data=LeafLength)

summary(anova)
## 
## Error: id
##           Df Sum Sq Mean Sq F value   Pr(>F)    
## Temp       2   6614    3307  17.188 1.06e-05 ***
## CO2        1    214     214   1.113     0.30    
## Temp:CO2   2    396     198   1.028     0.37    
## Residuals 30   5772     192                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Error: id:Genotype
##                   Df Sum Sq Mean Sq F value  Pr(>F)   
## Genotype           1    871     871   2.016 0.16598   
## Temp:Genotype      2   7270    3635   8.409 0.00126 **
## CO2:Genotype       1     46      46   0.108 0.74522   
## Temp:CO2:Genotype  2   2673    1337   3.092 0.06013 . 
## Residuals         30  12968     432                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Error: id:Genotype:Time
##             Df Sum Sq Mean Sq F value Pr(>F)    
## Time        18  17707   983.7   140.2 <2e-16 ***
## Residuals 1278   8964     7.0                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

##Postanova CO2

bxp = ggboxplot(
  LeafLength, x = "Time", y = "LeafL",
  color = "CO2", palette = "jco"
)
pwc = LeafLength %>%
  group_by(Time) %>%
  pairwise_t_test(
    LeafL ~ CO2, paired = TRUE,
    p.adjust.method = "bonferroni"
  )
pwc = pwc %>% add_xy_position(x = "Time") 
bxp + 
  stat_pvalue_manual(pwc, tip.length = 0, hide.ns = TRUE) +
  labs(
    subtitle = paste("Anova, ","F(1)", " = ", "1.113, ", "p", " = ", "0.30"),
    caption = get_pwc_label(pwc)
  )

Análisis: Respecto al crecimiento: se observa que en concetración de 700 de CO2, la planta tiene un mayor crecimiento respecto a una concentración de 400 de CO2, es decir que a mayor concentración de CO2, la hoja tiene un mayor crecimiento, debido a que es una molécula que requiere el organismo para obtener una mayor longitud en cuanto a hojas, tallo e incluso raíz. De la misma manera, el gráfico indica que los puntos de mayor crecimiento de la hoja son el los primeros días porque es donde la hoja puede tener una mayor area para recibir los nutrientes que se necesitan para funciones biológicas del organismo, posteriormente, el área foliar ya no presenta un crecimiento significativo porque ya no tiene la necesidad de crecer en tamaño porque la energía que se requiere está direccionada a otros procesos biológicos.

##POstanova Temp

bxp = ggboxplot(
  LeafLength, x = "Time", y = "LeafL",
  color = "Temp", palette = "jco"
)
pwc = LeafLength %>%
  group_by(Time) %>%
  pairwise_t_test(
    LeafL ~ Temp, paired = TRUE,
    p.adjust.method = "bonferroni"
  )
pwc = pwc %>% add_xy_position(x = "Time") 
bxp + 
  stat_pvalue_manual(pwc, tip.length = 0, hide.ns = TRUE) +
  labs(
    subtitle = paste("Anova, ","F(2)", " = ", "17.188 , ", "p", " = ", "<0.0001 "),
    caption = get_pwc_label(pwc)
  )

Análisis: Respecto a la temperatura y el crecimiento, se observa que cada punto es significativo, eso quiere decir que la variable temperatura esta muy ligada al crecimiento en el área foliar de la planta cuando esta se encuentra en un entorno de 31 a 32.

##Postanova Temp-Genotipo

bxp = ggboxplot(
  LeafLength, x = "Time", y = "LeafL",
  title= "Leaf Length",
  xlab ="time (days)", ylab= "Length (cm)",
  color = "Temp", palette = "lancet",
  facet.by = "Genotype"
)

pwc = LeafLength %>%
  group_by(Time, Genotype) %>%
  pairwise_t_test(
    LeafL ~ Temp, paired = TRUE,
    p.adjust.method = "bonferroni"
  )


pwc = pwc %>% add_xy_position(x = "Time") 
bxp + 
  stat_pvalue_manual(pwc, tip.length = 0, hide.ns = TRUE) +
  labs(
    subtitle = paste("Anova, ","F(2)", " = ", "8.409 , ", "p", " = ", "0.00126"),
    caption = get_pwc_label(pwc)
  )