Ejemplo Clase

library(agricolae)

mi_audps <- function(t, y){
  audps(y, t)
}

tiempos <- seq(7, 70, 7)
daño <- sort(runif(length(tiempos), 
                  min =5, 80))
mi_audps(tiempos, daño)
## evaluation 
##   2336.699
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/Sergio/Desktop/Asignacion3/datosaudps.xlsx")


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 16.194952    1
## 2  14 27.453993    1
## 3  21 47.861721    1
## 4  28 53.341319    1
## 5  35 59.049806    1
## 6  42 60.251473    1
## 7  49 61.134983    1
## 8  56 72.556536    1
## 9  63 74.701224    1
## 10 70 77.507401    1
## 11  7  6.213111    2
## 12 14  9.927976    2
## 13 21 10.880154    2
## 14 28 11.017487    2
## 15 35 11.456954    2
## 16 42 12.800531    2
## 17 49 45.099033    2
## 18 56 49.715720    2
## 19 63 64.364605    2
## 20 70 70.031892    2
## 21  7 19.076662    3
## 22 14 20.449995    3
## 23 21 34.421369    3
## 24 28 34.661702    3
## 25 35 51.601764    3
## 26 42 55.112918    3
## 27 49 60.782495    3
## 28 56 62.329783    3
## 29 63 72.842647    3
## 30 70 79.908444    3
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')

Asigación

Plotly con ggplot

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
library(tidyr)
library(plyr)
## 
## Attaching package: 'plyr'
## The following objects are masked from 'package:plotly':
## 
##     arrange, mutate, rename, summarise
data1 <- dfg
data1 <- rename(data1, c("1" = "Trat_1", "2" = "Trat_2", "3" = "Trat_3"))
## The following `from` values were not present in `x`: 1, 2, 3
plotis <- ggplot(data = dfg, aes(x = t, y = y)) + geom_line(aes(colour=as.factor(trat))) + labs(x = 'Tiempo', y = 'Daño', title = 'audps')
plotis <- plotis + facet_wrap( ~ trat, ncol=3)
dassar<-ggplotly(plotis)
## Warning: `group_by_()` is deprecated as of dplyr 0.7.0.
## Please use `group_by()` 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.
dassar <- dassar %>% layout(legend=list(title=list(text='<b> Tratamiento </b>')))
dassar

Plotly

library(plotly)
library(tidyr)
library(plyr)

data <- spread(dfg, trat, y)
data
##     t        1         2        3
## 1   7 16.19495  6.213111 19.07666
## 2  14 27.45399  9.927976 20.45000
## 3  21 47.86172 10.880154 34.42137
## 4  28 53.34132 11.017487 34.66170
## 5  35 59.04981 11.456954 51.60176
## 6  42 60.25147 12.800531 55.11292
## 7  49 61.13498 45.099033 60.78249
## 8  56 72.55654 49.715720 62.32978
## 9  63 74.70122 64.364605 72.84265
## 10 70 77.50740 70.031892 79.90844
data <- rename(data, c("1" = "Trat_1", "2" = "Trat_2", "3" = "Trat_3"))

fig <- plot_ly(data, x = ~t, y = ~Trat_1, type = 'scatter', mode = 'lines', name = 'Trat_1', line = list(color=rgb(0.9,0.8,0.3)))
fig <- fig %>% add_trace(y = ~Trat_2, name = 'trat_2', line = list(color=rgb(0.8,0.3,0.2)))
fig <- fig %>% add_trace(y = ~Trat_3, name = 'trat_3', line = list(color=rgb(0.3,0.4,0.8)))

f <- list(
  family = "Courier New, monospace",
  size = 18,
  color = "#7f7f7f"
)
x <- list(
  title = "Tiempo",
  titlefont = f
)
y <- list(
  title = "Daño",
  titlefont = f
)
fig <- fig %>% layout(xaxis = x, yaxis = y)

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.

ggpubr, barplot

library(ggpubr)
## 
## Attaching package: 'ggpubr'
## The following object is masked from 'package:plyr':
## 
##     mutate
dfg
##     t         y trat
## 1   7 16.194952    1
## 2  14 27.453993    1
## 3  21 47.861721    1
## 4  28 53.341319    1
## 5  35 59.049806    1
## 6  42 60.251473    1
## 7  49 61.134983    1
## 8  56 72.556536    1
## 9  63 74.701224    1
## 10 70 77.507401    1
## 11  7  6.213111    2
## 12 14  9.927976    2
## 13 21 10.880154    2
## 14 28 11.017487    2
## 15 35 11.456954    2
## 16 42 12.800531    2
## 17 49 45.099033    2
## 18 56 49.715720    2
## 19 63 64.364605    2
## 20 70 70.031892    2
## 21  7 19.076662    3
## 22 14 20.449995    3
## 23 21 34.421369    3
## 24 28 34.661702    3
## 25 35 51.601764    3
## 26 42 55.112918    3
## 27 49 60.782495    3
## 28 56 62.329783    3
## 29 63 72.842647    3
## 30 70 79.908444    3
dfg$trat <- as.factor(dfg$trat)
dfg$t <- rownames(dfg)
ggbarplot(dfg, x = 't', y = 'y',
          xlab = 'Tiempo', ylab = 'Daño',
          fill = "trat",               
          color = "white")