Correr la paquetería

if(!require(pacman))
  install.packages("pacman")
## Cargando paquete requerido: pacman
## Warning: package 'pacman' was built under R version 4.4.3
library("pacman")

p_load("vroom",
       "dplyr",
       "ggplot2",
       "tidyr",
       "ggrepel", 
       "plotly")

Llamar a la base de datos

Melting_curves <- vroom(file = "https://raw.githubusercontent.com/ManuelLaraMVZ/resultados_PCR_practica/refs/heads/main/Disociaci%C3%B3n_Grupo1_17022024.csv")
## Rows: 61 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (7): Temperature, A1, B1, C1, D1, E1, F1
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Melting_curves
## # A tibble: 61 × 7
##    Temperature    A1    B1    C1    D1    E1    F1
##          <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
##  1        65   7376. 3875. 9643. 3732. 4066. 7145.
##  2        65.5 7371. 3870. 9602. 3729. 4057. 7068.
##  3        66   7366. 3865. 9561. 3727. 4048. 6991.
##  4        66.5 7360. 3859. 9520. 3725. 4039. 6914.
##  5        67   7355. 3854. 9478. 3723. 4030. 6837.
##  6        67.5 7350. 3849. 9437. 3721. 4021. 6760.
##  7        68   7345. 3843. 9396. 3719. 4013. 6682.
##  8        68.5 7321. 3836. 9332. 3715. 4002. 6595.
##  9        69   7280. 3826. 9246. 3711. 3990. 6503.
## 10        69.5 7224. 3816. 9145. 3705. 3977. 6408.
## # ℹ 51 more rows
Melting_curves2 <- Melting_curves %>% 
  mutate(Temperatura=Temperature, PPBA=A1, ZARX=B1, FFSS=C1, LANS=D1, Negativo=E1, D2MI=F1) %>% select(-Temperature:-F1) 
Melting_curves2
## # A tibble: 61 × 7
##    Temperatura  PPBA  ZARX  FFSS  LANS Negativo  D2MI
##          <dbl> <dbl> <dbl> <dbl> <dbl>    <dbl> <dbl>
##  1        65   7376. 3875. 9643. 3732.    4066. 7145.
##  2        65.5 7371. 3870. 9602. 3729.    4057. 7068.
##  3        66   7366. 3865. 9561. 3727.    4048. 6991.
##  4        66.5 7360. 3859. 9520. 3725.    4039. 6914.
##  5        67   7355. 3854. 9478. 3723.    4030. 6837.
##  6        67.5 7350. 3849. 9437. 3721.    4021. 6760.
##  7        68   7345. 3843. 9396. 3719.    4013. 6682.
##  8        68.5 7321. 3836. 9332. 3715.    4002. 6595.
##  9        69   7280. 3826. 9246. 3711.    3990. 6503.
## 10        69.5 7224. 3816. 9145. 3705.    3977. 6408.
## # ℹ 51 more rows
Melting_curves3 <- Melting_curves2 %>% 
  pivot_longer(cols=-Temperatura,
               names_to = "Muestras", 
               values_to = "Fluorescencias")
Melting_curves3
## # A tibble: 366 × 3
##    Temperatura Muestras Fluorescencias
##          <dbl> <chr>             <dbl>
##  1        65   PPBA              7376.
##  2        65   ZARX              3875.
##  3        65   FFSS              9643.
##  4        65   LANS              3732.
##  5        65   Negativo          4066.
##  6        65   D2MI              7145.
##  7        65.5 PPBA              7371.
##  8        65.5 ZARX              3870.
##  9        65.5 FFSS              9602.
## 10        65.5 LANS              3729.
## # ℹ 356 more rows
Grafica_melting <- ggplot(Melting_curves3,
                          aes(x = Temperatura,
                              y = Fluorescencias,
                              color = Muestras))+
  geom_line(linewidht = 1.5)+
  theme_classic()+
  labs(title = "Curvas de disociación",
       subtitle = "Todas las muestras",
       caption = "Diseñó: Equipo LANS",
       x = "Temperatura (°C)",
       Y = "Fluorescencia (u.a.)")+
  theme(axis.line = element_line (size = 1.2, color = "black"),
        axis.title = element_text(face = "bold"),
        axis.text = element_text(face = "bold"),
        legend.title = element_text(face = "bold"),
        legend.text = element_text(face = "bold"))
## Warning in geom_line(linewidht = 1.5): Ignoring unknown parameters: `linewidht`
## Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
## ℹ Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
Grafica_melting

Dervidas de las curvas de disociación

Derivadas <- Melting_curves2 %>% 
  mutate(across(PPBA:D2MI, 
                ~ c(NA, diff(.x) / diff(Melting_curves2$Temperatura)), 
                .names = "d_{.col}")) %>% 
  slice(-1)  # Elimina la primera fila con NA

Derivadas
## # A tibble: 60 × 13
##    Temperatura  PPBA  ZARX  FFSS  LANS Negativo  D2MI d_PPBA d_ZARX d_FFSS
##          <dbl> <dbl> <dbl> <dbl> <dbl>    <dbl> <dbl>  <dbl>  <dbl>  <dbl>
##  1        65.5 7371. 3870. 9602. 3729.    4057. 7068.  -10.4  -10.7  -82.5
##  2        66   7366. 3865. 9561. 3727.    4048. 6991.  -10.4  -10.7  -82.5
##  3        66.5 7360. 3859. 9520. 3725.    4039. 6914.  -10.4  -10.7  -82.5
##  4        67   7355. 3854. 9478. 3723.    4030. 6837.  -10.4  -10.7  -82.5
##  5        67.5 7350. 3849. 9437. 3721.    4021. 6760.  -10.4  -10.7  -82.5
##  6        68   7345. 3843. 9396. 3719.    4013. 6682.  -10.4  -10.7  -82.5
##  7        68.5 7321. 3836. 9332. 3715.    4002. 6595.  -46.5  -15.2 -128. 
##  8        69   7280. 3826. 9246. 3711.    3990. 6503.  -82.2  -19.5 -171. 
##  9        69.5 7224. 3816. 9145. 3705.    3977. 6408. -112.   -20.9 -204. 
## 10        70   7156. 3804. 9030. 3699.    3964. 6312. -137.   -22.9 -228. 
## # ℹ 50 more rows
## # ℹ 3 more variables: d_LANS <dbl>, d_Negativo <dbl>, d_D2MI <dbl>

Reordenar los datos

Derivadas2 <- Derivadas %>% 
  select(Temperatura, starts_with("d_")) %>%  # Solo mantiene las derivadas
  pivot_longer(cols = -Temperatura, 
               names_to = "Muestras",
               values_to = "Derivadas")

Derivadas2
## # A tibble: 360 × 3
##    Temperatura Muestras   Derivadas
##          <dbl> <chr>          <dbl>
##  1        65.5 d_PPBA        -10.4 
##  2        65.5 d_ZARX        -10.7 
##  3        65.5 d_FFSS        -82.5 
##  4        65.5 d_LANS         -4.34
##  5        65.5 d_Negativo    -17.7 
##  6        65.5 d_D2MI       -154.  
##  7        66   d_PPBA        -10.4 
##  8        66   d_ZARX        -10.7 
##  9        66   d_FFSS        -82.5 
## 10        66   d_LANS         -4.34
## # ℹ 350 more rows

Gráficas Derivadas

Grafica_derivada <- ggplot(Derivadas2,
                           aes(x = Temperatura,
                               y = -Derivadas,  # Invertimos el signo de las derivadas
                               color = Muestras)) +
  geom_line(linewidth = 1.5) +  # Corregimos "linewidht" a "linewidth"
  theme_classic() +
  labs(title = "Curvas de la derivada de disociación",
       subtitle = "Todas las muestras",
       caption = "Diseño: Equipo LANS",
       x = "Temperatura (°C)",
       y = expression(Delta*F/Delta*T)) +  # Eliminamos el signo negativo en la etiqueta del eje Y
  theme(axis.line = element_line(size = 1.2, color = "black"),
        axis.title = element_text(face = "bold"),
        axis.text = element_text(face = "bold"),
        legend.title = element_text(face = "bold"),
        legend.text = element_text(face = "bold")) +
  scale_x_continuous(breaks = seq(min(Derivadas2$Temperatura), 
                                  max(Derivadas2$Temperatura), 
                                  by = 3))

Grafica_derivada

Contruir gráfica 3D

library(plotly)

Grafica_derivada_3D <- plot_ly(Derivadas2,
                               x = ~Temperatura,  
                               y = ~Muestras,    
                               z = ~-Derivadas,  
                               color = ~factor(Muestras),  
                               type = "scatter3d",
                               mode = "lines",
                               line = list(width = 6))%>%
  layout(scene = list(
    xaxis = list(title = "Temperatura (°C)"),
    yaxis = list(title = "Muestras"),
    zaxis = list(title = "−ΔT/ΔF")
  ))
Grafica_derivada_3D

Gráfica del equipo 6

Grafica_derivada_equipo6 <- ggplot(Derivadas,
                                   aes(x = Temperatura))+
  geom_line(aes(y= -d_LANS, color = "d_LANS"), linewidth = 1.5)+
  geom_line(aes(y= -d_ZARX, color = "d_ZARX"), linewidth = 1.5)+
scale_color_manual(values = c("d_LANS" = "blue", "d_ZARX"= "#ceee29"))+
  theme_classic()+
  labs(title= "Derivada de disociación",
       subtitle= "Tejido: hígado", 
       caption= "Diseñó: Equipo 6:LANS",
       x= "Temperatura",
       y = expression(-Delta*F/Delta*T)) +
  theme(axis.line = element_line (size = 1.2, color = "black"),
        axis.title = element_text(face = "bold"),
        axis.text = element_text(face = "bold"),
        legend.title = element_text(face = "bold"),
        legend.text = element_text(face = "bold"))+
  scale_x_continuous(breaks = seq(min(Derivadas2$Temperatura), 
                                  max(Derivadas2$Temperatura), 
                                  by = 3))

Grafica_derivada_equipo6

Etiqueta

Pico <- min(Derivadas$d_LANS)
Pico
## [1] -16.1747

Temperatura

Tm <- Derivadas %>% 
  filter(d_LANS == Pico) %>% 
  select(Temperatura, d_LANS)
Tm
## # A tibble: 1 × 2
##   Temperatura d_LANS
##         <dbl>  <dbl>
## 1          78  -16.2

Gráfica con etiqueta d_LANS

Grafica_derivada_equipo6.2 <- Grafica_derivada_equipo6 +
  geom_vline(xintercept = Tm$Temperatura, 
             color = "#9b7ae7",
             linetype = "dashed", 
             linewidth = 1) +
  geom_label_repel(data = Tm, 
                   aes(x = Temperatura, y = d_LANS, 
                       label = paste("TM =", round(Temperatura), "°C")), 
                   nudge_x = 4, 
                   nudge_y = -0.09, 
                   max.overlaps = 100, 
                   color = "black", 
                   fill = "#d3c8ed")

Grafica_derivada_equipo6.2

d_ZARX

Pico_zarx <- min(Derivadas$d_ZARX)
Pico_zarx
## [1] -43.78384

Tm ZARX

Tm_ZARX <- Derivadas %>% 
  filter(d_ZARX == Pico_zarx) %>% 
  select(Temperatura, d_ZARX)
Tm_ZARX
## # A tibble: 1 × 2
##   Temperatura d_ZARX
##         <dbl>  <dbl>
## 1        80.5  -43.8

Gráfica con etiqueta ZARX

Grafica_derivada_equipo6.3 <- Grafica_derivada_equipo6 +
  geom_vline(xintercept = Tm_ZARX$Temperatura, 
             color = "#9b7ae7",
             linetype = "dashed", 
             linewidth = 1) +
  geom_label_repel(data = Tm_ZARX, 
                   aes(x = Temperatura, y = d_ZARX, 
                       label = paste("TM =", round(Temperatura), "°C")), 
                   nudge_x = 4, 
                   nudge_y = -0.2, 
                   max.overlaps = 100, 
                   color = "black", 
                   fill = "#d3c8ed")

Grafica_derivada_equipo6.3

d_Negativo

Pico_Negativo <- min(Derivadas$d_Negativo)
Pico_Negativo
## [1] -27.70628

Tm_Negativo

Tm_Negativo <- Derivadas %>% 
  filter(d_Negativo == Pico_Negativo) %>% 
  select(Temperatura, d_Negativo)
Tm_Negativo
## # A tibble: 1 × 2
##   Temperatura d_Negativo
##         <dbl>      <dbl>
## 1        70.5      -27.7

Gráfica d_Negativo vs d_LANS

Grafica_derivada_equipo6.NL <- ggplot(Derivadas,
                                   aes(x = Temperatura))+
  geom_line(aes(y= -d_LANS, color = "d_LANS"), linewidth = 1.5)+
  geom_line(aes(y= -d_Negativo, color = "d_Negativo"), linewidth = 1.5)+
scale_color_manual(values = c("d_LANS" = "blue", "d_Negativo"= "#42c1c0"))+
  theme_classic()+
  labs(title= "Derivada de disociación",
       subtitle= "Tejido: hígado", 
       caption= "Diseñó: Equipo 6:LANS",
       x= "Temperatura",
       y = expression(-Delta*F/Delta*T)) +
  theme(axis.line = element_line (size = 1.2, color = "black"),
        axis.title = element_text(face = "bold"),
        axis.text = element_text(face = "bold"),
        legend.title = element_text(face = "bold"),
        legend.text = element_text(face = "bold"))+
  scale_x_continuous(breaks = seq(min(Derivadas2$Temperatura), 
                                  max(Derivadas2$Temperatura), 
                                  by = 3))

Grafica_derivada_equipo6.NL

Gráfica d_Negativo vs d_LANS

Grafica_derivada_equipo6.4 <- Grafica_derivada_equipo6.NL +
  geom_vline(xintercept = Tm_Negativo$Temperatura, 
             color = "#9b7ae7",
             linetype = "dashed", 
             linewidth = 1) +
  geom_label_repel(data = Tm_Negativo, 
                   aes(x = Temperatura, y = d_Negativo, 
                       label = paste("TM =", round(Temperatura), "°C")), 
                   nudge_x = 4, 
                   nudge_y = -0.03, 
                   max.overlaps = 100, 
                   color = "black", 
                   fill = "#d3c8ed")+
  geom_vline(xintercept = Tm$Temperatura,
             color = "#e74220",
             linetype = "dashed",
             linewidth = 1)+
  geom_label_repel(data = Tm,
                   aes(x = Temperatura, y= d_LANS,
                       label = paste("TM =", round(Temperatura),"°C")),
                   nudge_x = 4,
                   nudge_y = -0.03,
                   max.overlaps = 100,
                   color = "black",
                   fill = "#c6f9a8")

Grafica_derivada_equipo6.4