library(agricolae)
dates<-c(14,21,28) # days
# example 1: evaluation - vector
evaluation<-c(40,80,90)
audps(evaluation,dates)
## evaluation 
##       1470
audps(evaluation,dates,"relative")
## evaluation 
##        0.7
x<-seq(10.5,31.5,7)
y<-c(40,80,90,90)
plot(x,y,"s",ylim=c(0,100),xlim=c(10,32),axes=FALSE,col="red" ,ylab="",xlab="")
title(cex.main=0.8,main="Absolute or Relative AUDPS\nTotal area=(31.5-10.5)*100=2100",
ylab="evaluation",xlab="dates" )
points(x,y,type="h")
z<-c(14,21,28)
points(z,y[-3],col="blue",lty=2,pch=19)
points(z,y[-3],col="blue",lty=2,pch=19)
axis(1,x,pos=0)
axis(2,c(0,40,80,90,100),las=2)
text(dates,evaluation+5,dates,col="blue")
text(14,20,"A = (17.5-10.5)*40",cex=0.8)
text(21,40,"B = (24.5-17.5)*80",cex=0.8)
text(28,60,"C = (31.5-24.5)*90",cex=0.8)
text(14,95,"audps = A+B+C = 1470")
text(14,90,"relative = audps/area = 0.7")

# It calculates audpc absolute
absolute<-audps(evaluation,dates,type="absolute")
print(absolute)
## evaluation 
##       1470
library(agricolae)
dates<-c(14,21,28) # days
# example 1: evaluation - vector
evaluation<-c(40,80,90)
audps(evaluation,dates)
## evaluation 
##       1470
audps(evaluation,dates,"relative")
## evaluation 
##        0.7
mi_audps <- function(t,y){
  audps(y,t)
}
tiempos <- seq(7,70,7)
daño <- sort(runif(n=length(tiempos),
                   min=5,20))
mi_audps(tiempos,daño)
## evaluation 
##    916.031
mi_trat_audps <- function(yt){
  salida = c()
  t <- unlist(yt[,1])
  for(i in seq(2,ncol(yt))){
    salida[i] <- mi_audps(t=t,y=unlist(yt[,i]))
  }
  salida <- salida[-1]
  return(salida)
}
library(readxl)
df_da <- read_excel("c:/Users/zishe/Downloads/datos_audps.xlsx")
df_da
## # A tibble: 10 x 4
##    Tiempo  D_t1  D_t2  D_t3
##     <dbl> <dbl> <dbl> <dbl>
##  1      7  20.1  6.25  7.85
##  2     14  26.0 16.3  30.5 
##  3     21  27.0 17.8  36.5 
##  4     28  30.4 25.6  44.3 
##  5     35  42.8 33.0  47.8 
##  6     42  43.1 61.2  50.3 
##  7     49  55.5 65.9  67.7 
##  8     56  60.2 74.0  73.7 
##  9     63  66.4 74.9  77.8 
## 10     70  66.8 78.6  79.2
audps_trat <- mi_trat_audps(df_da)

dfg <- data.frame(t = rep(df_da$Tiempo, 3),
                 y = c(df_da$D_t1,df_da$D_t2,df_da$D_t3),
                 trat = rep(1:3, each=nrow(df_da)));dfg
##     t         y trat
## 1   7 20.106662    1
## 2  14 25.982238    1
## 3  21 26.977905    1
## 4  28 30.397504    1
## 5  35 42.842189    1
## 6  42 43.126011    1
## 7  49 55.543229    1
## 8  56 60.240028    1
## 9  63 66.381115    1
## 10 70 66.790826    1
## 11  7  6.252022    2
## 12 14 16.329997    2
## 13 21 17.769707    2
## 14 28 25.611438    2
## 15 35 32.961058    2
## 16 42 61.224250    2
## 17 49 65.927915    2
## 18 56 74.026002    2
## 19 63 74.891202    2
## 20 70 78.638112    2
## 21  7  7.847377    3
## 22 14 30.457015    3
## 23 21 36.451613    3
## 24 28 44.318522    3
## 25 35 47.804498    3
## 26 42 50.306253    3
## 27 49 67.715537    3
## 28 56 73.680380    3
## 29 63 77.832423    3
## 30 70 79.214911    3
df_texto <- data.frame(label = round(audps_trat,2), 
                       trat = 1:3);df_texto
##     label trat
## 1 3068.71    1
## 2 3175.42    2
## 3 3609.40    3
df_da$Tiempo
##  [1]  7 14 21 28 35 42 49 56 63 70
df_da[,1]
## # A tibble: 10 x 1
##    Tiempo
##     <dbl>
##  1      7
##  2     14
##  3     21
##  4     28
##  5     35
##  6     42
##  7     49
##  8     56
##  9     63
## 10     70
unlist(df_da[,1])
##  Tiempo1  Tiempo2  Tiempo3  Tiempo4  Tiempo5  Tiempo6  Tiempo7  Tiempo8 
##        7       14       21       28       35       42       49       56 
##  Tiempo9 Tiempo10 
##       63       70
class(df_da$Tiempo)
## [1] "numeric"
class(df_da[,1])
## [1] "tbl_df"     "tbl"        "data.frame"
class(unlist(df_da[,1]))
## [1] "numeric"
library(ggplot2)
ggplot(data = dfg, aes(x = t, y = y))+
  geom_line()+
  geom_text(data = df_texto,
            mapping = aes(x = 20, y = 60, label = label))+
  facet_wrap(~trat)

library(lattice)
xyplot(y~t|trat, data = dfg, t='l')

library(ggpubr)
dfg$trat <- as.factor(dfg$trat)
dfg$t <- rownames(dfg)
ggviolin(dfg, x = "trat", y = "y", fill = "trat",
         palette = c("cyan","darkgoldenrod1","firebrick1"),
         add = "boxplot",
         add.params = list(fill = "white"),
         ylab = 'Daño',
         xlab = 'Tratamiento',
         width = 0.8,
         ggtheme = theme_dark())

library(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
fig <- plot_ly(dfg, x = df_da$Tiempo, y = df_da$D_t1, type = 'bar', name = 'Trat1',
        marker = list(color = 'chocolate3'))
fig <- fig %>% add_trace(y = df_da$D_t2, name = 'Trat2', marker = list(color = 'cyan3'))
fig <- fig %>% add_trace(y = df_da$D_t3, name = 'Trat3', marker = list(color = 'firebrick2'))
fig <- fig %>% layout(title = 'Daño en plantas según tratamiento',
         xaxis = list(
           title = "Tiempo en Días",
           tickfont = list(
             size = 14,
             color = 'chocolate3')),
         yaxis = list(
           title = 'Daño',
           titlefont = list(
             size = 16,
             color = 'cyan3'),
           tickfont = list(
             size = 14,
             color = 'firebrick2')),
         legend = list(x = 0, y = 1, bgcolor = 'white', bordercolor = 'black'),
         barmode = 'group', bargap = 0.15, bargroupgap = 0.1)

fig
## Warning: `arrange_()` is deprecated as of dplyr 0.7.0.
## Please use `arrange()` instead.
## See vignette('programming') for more help
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
## Warning: 'layout' objects don't have these attributes: 'bargroupgap'
## Valid attributes include:
## 'font', 'title', 'uniformtext', 'autosize', 'width', 'height', 'margin', 'paper_bgcolor', 'plot_bgcolor', 'separators', 'hidesources', 'showlegend', 'colorway', 'datarevision', 'uirevision', 'editrevision', 'selectionrevision', 'template', 'modebar', 'meta', 'transition', '_deprecated', 'clickmode', 'dragmode', 'hovermode', 'hoverdistance', 'spikedistance', 'hoverlabel', 'selectdirection', 'grid', 'calendar', 'xaxis', 'yaxis', 'ternary', 'scene', 'geo', 'mapbox', 'polar', 'radialaxis', 'angularaxis', 'direction', 'orientation', 'editType', 'legend', 'annotations', 'shapes', 'images', 'updatemenus', 'sliders', 'colorscale', 'coloraxis', 'metasrc', 'barmode', 'bargap', 'mapType'