Correr la paqueteria

if(!require(pacman))
  install.packages("pacman")
## Loading required package: pacman
library("pacman")
p_load("vroom",
       "dplyr",
       "ggplot2",
       "tidyr",
       "ggrepel",
       "plotly")

Llamar 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, 
         PPBA = A1,
         ZARX = B1,
         FSFS = C1,
         LANS = D1,
         Negativo = E1,
         D2MI = F1) %>% 
  select(-Temperature:-F1) %>% 
  filter(Temperatura>=6)

Melting_curves2
## # A tibble: 61 × 7
##    Temperatura  PPBA  ZARX  FSFS  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

Reordenar datod

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   FSFS              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 FSFS              9602.
## 10        65.5 LANS              3729.
## # ℹ 356 more rows

Grafica

Grafica_melting <- ggplot(Melting_curves3,
                          aes(x = Temperatura,
                              y = Fluorescencias,
                              color = Muestras)) +
  geom_line(linewidth = 1.5)+
  theme_classic()+
  labs(title = "Curvas de disociación",
       subtitle = "Todas las muestras",
       caption = "Diseño: FSFS",
       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: 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

Derivadas de las curvas

Derivadas <-  Melting_curves2 %>% 
  mutate(across(PPBA:D2MI, 
                ~ -c(NA, diff(.x)/diff(Melting_curves2$Temperatura)), .names = "d_{.col}")) %>% 
  select(-PPBA:-D2MI) %>% 
  slice(-1)
Derivadas
## # A tibble: 60 × 7
##    Temperatura d_PPBA d_ZARX d_FSFS d_LANS d_Negativo 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_PPBA         10.4 
##  2        65.5 d_ZARX         10.7 
##  3        65.5 d_FSFS         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_FSFS         82.5 
## 10        66   d_LANS          4.34
## # ℹ 350 more rows

Gráficas Derivadas

Grafica_derivada <- ggplot(Derivadas2,
                           aes(x = Temperatura,
                               y = Derivadas,
                               color = Muestras)) +
  geom_line(linewidth = 1.5) +
  theme_classic() +
  labs(title = "De la derivada de disociación",
       subtitle = "Todas las muestras",
       caption = "Diseño: FSFS",
       x = "Temperatura (°C)",
       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(floor(min(Derivadas2$Temperatura)), 
                                  ceiling(max(Derivadas2$Temperatura)), 
                                  by = 2.5))
Grafica_derivada

Construir una gráfica 3D

Grafica_derivada_3D <- plot_ly(Derivadas2,
                               x = ~Temperatura,
                               y = ~Muestras,
                               z = ~Derivadas,
                               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 = "Muestras"),
           zaxis = list(title = "-ΔT/ΔF")
         ))
Grafica_derivada_3D

Grafica individual

Grafica_derivada_equipo <- ggplot(Derivadas,
                                  aes(x = Temperatura))+
 geom_line(aes(y = d_FSFS, color = "d_FSFS"), linewidth = 1.2) + 
  geom_line(aes(y = d_D2MI, color = "d_D2MI"), linewidth = 1.5) + 
  geom_line(aes(y = d_Negativo, color = "d_Negativo"), linewidth = 1.5) + 
  theme_classic()+
  scale_color_manual(values = c("d_FSFS" = "#784F41", 
                               "d_D2MI" = "#e2a3c7", 
                               "d_Negativo" = "#678d58",
                               "d_Control" = "#afd2e9"))+
  labs(title = "Derivada de Disociación",
       subtitle = "Tejido: Corazón",
       caption = "Diseño: FSFS",
       x = "Temperatura (°C)",
       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(floor(min(Derivadas$Temperatura)), 
                                  ceiling(max(Derivadas$Temperatura)), 
                                  by = 2.5))
Grafica_derivada_equipo

Etiquetas

Pico <- max(Derivadas$d_FSFS)
Pico
## [1] 939.9215
Tm <- Derivadas %>% 
  filter(d_FSFS == Pico) %>% 
  select(Temperatura, d_FSFS)
Tm
## # A tibble: 1 × 2
##   Temperatura d_FSFS
##         <dbl>  <dbl>
## 1          82   940.

Grafica con etiqueta

Grafica_derivada_equipo2 <- Grafica_derivada_equipo+
  geom_vline(xintercept = Tm$Temperatura, 
             color = "black", 
             linetype = "dashed", 
             linewidth = 1) +
  geom_label_repel(data = Tm,
                   aes(x = Temperatura,
                       y = d_FSFS,
                       label = paste("Tm = ", round(Temperatura), "°C")),
                   nudge_x = 10,
                   nudge_y = 5,
                   max.overlaps = 10,
                   color = "black",
                   fill = "white")
Grafica_derivada_equipo2