Librería Agricolae

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
rm(evaluation,dates,absolute)
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) 
dano=sort(runif(n=length(tiempos),
                min=5,80))

mi_audps(tiempos,dano)
## evaluation 
##   3768.107

Matriz de Excel y uso de librerías ggplot y lattice

mi_trat_audps <- function(yt){ 
  salida = c() 
  t =unlist(yt[,1]) 
  print(t) 
  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("enfer.xlsx") 
df_da 
## # A tibble: 10 x 4
##    tiempo  D_t1  D_t2  D_t3
##     <dbl> <dbl> <dbl> <dbl>
##  1      7  11.6  22.3  10.8
##  2     14  17.0  42.0  21.1
##  3     21  18.9  42.6  30.9
##  4     28  23.3  48.0  32.8
##  5     35  45.4  49.0  41.6
##  6     42  45.5  62.0  47.9
##  7     49  54.6  67.3  51.4
##  8     56  67.9  73.8  60.1
##  9     63  75.8  79.4  61.8
## 10     70  77.7  79.5  74.6
mi_trat_audps(df_da)
##  tiempo1  tiempo2  tiempo3  tiempo4  tiempo5  tiempo6  tiempo7  tiempo8 
##        7       14       21       28       35       42       49       56 
##  tiempo9 tiempo10 
##       63       70
## [1] 3064.596 3961.328 3031.767
audps_trat = mi_trat_audps(df_da) 
##  tiempo1  tiempo2  tiempo3  tiempo4  tiempo5  tiempo6  tiempo7  tiempo8 
##        7       14       21       28       35       42       49       56 
##  tiempo9 tiempo10 
##       63       70
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))) 
df_texto = data.frame(label = round(audps_trat,2), trat = 1:3)


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')

ASIGNACIÓN

Gráfica con librería ggpubr

library(ggpubr)
daño<-round(dfg$y,2)
tiempo<-round(dfg$t,2)
Tratamiento<-as.character(dfg$trat)
datosg1<-data.frame(tiempo,Tratamiento,daño)
df_texto <- data.frame(label = round(audps_trat,2), trat = 1:3)

ggline(datosg1,x="tiempo",y= "daño",linetype = "Tratamiento",shape = "Tratamiento",
       ylab = "Daño (%)",color = "Tratamiento",xlab = "Tiempo (días)",
       main="Curva de progreso de la enfermedad",cex.main=3,facet.by ="Tratamiento",ggtheme = theme_grey(base_size = 12),label=nrow(df_texto)+
  facet_wrap(~Tratamiento),font.label=list(size=14,face="italic",color="black"),legend="bottom",palette = c("#00AFBB", "#E7B800","#8E44AD")) +
    theme(plot.title = element_text(hjust = 0.5)) 

Gráfica con librería plotly

Instalamos el paquete plyr y plotly.

library(plyr)
abc<-ddply(datosg1,c("Tratamiento","tiempo"),summarise,length=mean(daño))
library(plotly)
imag<- plot_ly(abc, x = ~tiempo, y = ~daño, mode = 'lines', linetype = ~Tratamiento, color = Tratamiento) 
imag<-imag %>% layout(title = 'Curva de progreso de la enfermedad',xaxis = list(title = 'Tiempo (días)'),yaxis = list (title = 'Daño (%)'))
imag
## 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.