Correr paquetes

if (!require(pacman))
  install.packages("pacman")
## Loading required package: pacman
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

Modificar la base de datos

Melting_curves2 <- Melting_curves%>%
mutate(Temperatura = Temperature, PPDA = A1, ZARX = B1, FSS = C1, LANS = D1, H2O = E1, D2MI = F1) %>%
select(-Temperature:-F1)
Melting_curves2
## # A tibble: 61 Ɨ 7
##    Temperatura  PPDA  ZARX   FSS  LANS   H2O  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

Agrupacion de datos

Melting_curves3 <- Melting_curves2 %>% 
  pivot_longer(cols = -Temperatura, 
               names_to = "Muestras",
               values_to = "Fluorescencia")
Melting_curves3
## # A tibble: 366 Ɨ 3
##    Temperatura Muestras Fluorescencia
##          <dbl> <chr>            <dbl>
##  1        65   PPDA             7376.
##  2        65   ZARX             3875.
##  3        65   FSS              9643.
##  4        65   LANS             3732.
##  5        65   H2O              4066.
##  6        65   D2MI             7145.
##  7        65.5 PPDA             7371.
##  8        65.5 ZARX             3870.
##  9        65.5 FSS              9602.
## 10        65.5 LANS             3729.
## # ℹ 356 more rows

Graficar

Grafica_melting <- ggplot(Melting_curves3,
                          aes( x = Temperatura,
                               y = Fluorescencia,
                               color = Muestras)) +
  geom_line(linewidth = 1.5)
Grafica_melting

Derivadas de las curvas de disociación

Derivadas <- Melting_curves2 %>% 
  mutate(across(PPDA:D2MI,
                 ~-c(NA, diff(.x)/diff(Melting_curves2$Temperatura)), .names = "d_{.col}")) %>% 
  select(-PPDA:-D2MI) %>% 
  slice(-1)
Derivadas
## # A tibble: 60 Ɨ 7
##    Temperatura d_PPDA d_ZARX d_FSS d_LANS d_H2O d_D2MI
##          <dbl>  <dbl>  <dbl> <dbl>  <dbl> <dbl>  <dbl>
##  1        65.5   10.4   10.7  82.5   4.34  17.7   154.
##  2        66     10.4   10.7  82.5   4.34  17.7   154.
##  3        66.5   10.4   10.7  82.5   4.34  17.7   154.
##  4        67     10.4   10.7  82.5   4.34  17.7   154.
##  5        67.5   10.4   10.7  82.5   4.34  17.7   154.
##  6        68     10.4   10.7  82.5   4.34  17.7   154.
##  7        68.5   46.5   15.2 128.    7.20  21.1   174.
##  8        69     82.2   19.5 171.    9.00  24.1   185.
##  9        69.5  112.    20.9 204.   11.1   25.3   190.
## 10        70    137.    22.9 228.   12.3   26.3   191.
## # ℹ 50 more rows

Reordenar los datos

Derivadas2 <- 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_PPDA       10.4 
##  2        65.5 d_ZARX       10.7 
##  3        65.5 d_FSS        82.5 
##  4        65.5 d_LANS        4.34
##  5        65.5 d_H2O        17.7 
##  6        65.5 d_D2MI      154.  
##  7        66   d_PPDA       10.4 
##  8        66   d_ZARX       10.7 
##  9        66   d_FSS        82.5 
## 10        66   d_LANS        4.34
## # ℹ 350 more rows

Graficas derivadas

Grafica_derivada <- ggplot(Derivadas2,
                           aes(x=Temperatura,
                               y=Derivadas,
                               color = Muestras)) + 
  geom_line(linewidth = 1.5)+
  theme_classic()+
labs(title = "Curvas de la derivada de disociacion",
     subtitle = "Todas las muestras",
     caption = "DiseƱo: Equipo 2",
     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 = 2))
## 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_derivada

Contruir una grafica 3D

Grafica_derivada_3D <- plot_ly(Derivadas2,
                               x= ~Temperatura,
                               y= ~Derivadas,
                               z= ~Muestras,
                               color= ~factor(Muestras),
                               type="scatter3d",
                               mode="lines",
                               line=list(width=6)) %>% 
  layout(title = "Curvas de derivada en 3D",
         scene= list(
           xaxis = list(title = "Temperatura (ĀŗC)"),
           yaxis = list(title = "Muestra"),
           zaxis = list(title = "-Δt/ΔF")
         ))
Grafica_derivada_3D

Grafica del equipo

Grafica_derivada_equipo <- ggplot(Derivadas,
                                  aes(x = Temperatura))+
  geom_line(aes(y = d_PPDA, color ="d_PPDA"), linewidth = 1.5) +
  geom_line(aes(y = d_H2O, color = "d_H2O"), linewidth = 1.5) +
  scale_color_manual(values = c("d_PPDA" = "green", "d_H2O"="blue")) + 
  theme_classic() + 
  labs(title = "Derivada de Disociación",
       subtitle = "Tejido: Cerebro, Testículo, Corazón e Hígado",
       caption = "Diseñó: Equipo 2",
       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 = 2))
Grafica_derivada_equipo

Etiquetas

pico <- max(Derivadas$d_PPDA) 
pico
## [1] 370.4117

Temperatura

tm <- Derivadas %>% 
  filter(d_PPDA == pico) %>% 
  select(Temperatura, d_PPDA)
tm
## # A tibble: 1 Ɨ 2
##   Temperatura d_PPDA
##         <dbl>  <dbl>
## 1          82   370.

GrƔfica con etiqueta

Grafica_derivada_equipo2 <- Grafica_derivada_equipo +
  geom_vline(xintercept = tm$Temperatura, 
             color = "red", 
             linetype = "dashed",
             linewidth = 1) +
  geom_label_repel(data = tm, 
                   aes(x = Temperatura,
                       y = d_PPDA,
                       label = paste("Tm = ", round(Temperatura), "ĀŗC")),
                   nudge_x = 4,
                   nudge_y = -0.3,
                   max.overlaps = 100,
                   color = "black",
                   fill = "lightblue")
Grafica_derivada_equipo2