if(!require(pacman))
  install.packages("pacman")
## Loading required package: pacman
library("pacman")

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

if(!require(pacman))
  install.packages("pacman")

library("pacman")


p_load("vroom",
       "dplyr",
       "ggplot2",
       "tidyr",
       "ggrepel")
melting_curves <- vroom(file="https://raw.githubusercontent.com/ManuelLaraMVZ/resultados_PCR_practica/refs/heads/main/Disociaci%C3%B3n_Grupo2_17022025.csv")
## Rows: 61 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (7): Temperature, A1, B1, C1, D1, E1, H1
## 
## ℹ 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    H1
##          <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
##  1        65   7448. 6822. 8564. 7347. 5628. 6126.
##  2        65.5 7418. 6860. 8557. 7266. 5599. 6067.
##  3        66   7388. 6897. 8550. 7185. 5570. 6008.
##  4        66.5 7358. 6934. 8543. 7104. 5541. 5949.
##  5        67   7328. 6971. 8536. 7022. 5513. 5890.
##  6        67.5 7298. 7009. 8529. 6941. 5484. 5831.
##  7        68   7268. 7046. 8522. 6860. 5455. 5772.
##  8        68.5 7222. 7072. 8499. 6769. 5418. 5707.
##  9        69   7161. 7083. 8458. 6673. 5377. 5639.
## 10        69.5 7089. 7075. 8399. 6574. 5332. 5568.
## # ℹ 51 more rows
melting_curves2 <- melting_curves %>%
mutate(Temperatura = Temperature,
Manuel = A1,
Regina = B1,
Marian = C1,
Ricardo = D1,
Neto = E1,
Johan = H1) %>%
select(-Temperature:-H1)


melting_curves2
## # A tibble: 61 × 7
##    Temperatura Manuel Regina Marian Ricardo  Neto Johan
##          <dbl>  <dbl>  <dbl>  <dbl>   <dbl> <dbl> <dbl>
##  1        65    7448.  6822.  8564.   7347. 5628. 6126.
##  2        65.5  7418.  6860.  8557.   7266. 5599. 6067.
##  3        66    7388.  6897.  8550.   7185. 5570. 6008.
##  4        66.5  7358.  6934.  8543.   7104. 5541. 5949.
##  5        67    7328.  6971.  8536.   7022. 5513. 5890.
##  6        67.5  7298.  7009.  8529.   6941. 5484. 5831.
##  7        68    7268.  7046.  8522.   6860. 5455. 5772.
##  8        68.5  7222.  7072.  8499.   6769. 5418. 5707.
##  9        69    7161.  7083.  8458.   6673. 5377. 5639.
## 10        69.5  7089.  7075.  8399.   6574. 5332. 5568.
## # ℹ 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   Manuel            7448.
##  2        65   Regina            6822.
##  3        65   Marian            8564.
##  4        65   Ricardo           7347.
##  5        65   Neto              5628.
##  6        65   Johan             6126.
##  7        65.5 Manuel            7418.
##  8        65.5 Regina            6860.
##  9        65.5 Marian            8557.
## 10        65.5 Ricardo           7266.
## # ℹ 356 more rows
grafica_melting <- ggplot(data = melting_curves3,
                             aes(x= Temperatura,
                                 y= Fluorescencias,
                                 color= Muestras))+
  geom_line(size=1.5)+
  theme_classic()+
  labs(title= "Curvas de disociación",
       subtitle= "Todas las muestras",
       caption= "Diseño: Ricardo Palos, Regina Hernández, Diego Campos",
       x= "Temperatura (°C)",
       y= "Fluorescencia (u.a.)")+
  theme(axis.line = element_line(size=1, 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: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## 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 negativas de las curvas de disociacion

derivadas<- melting_curves2 %>% 
  mutate(across(Manuel:Johan,
               ~-c(NA, diff(.x)/diff(melting_curves2$Temperatura)),
                .names = "d_{.col}")) %>% 
  select(-Manuel:-Johan) %>% 
  slice(-1)
derivadas
## # A tibble: 60 × 7
##    Temperatura d_Manuel d_Regina d_Marian d_Ricardo d_Neto d_Johan
##          <dbl>    <dbl>    <dbl>    <dbl>     <dbl>  <dbl>   <dbl>
##  1        65.5     59.8    -74.6     14.2      162.   57.6    118.
##  2        66       59.8    -74.6     14.2      162.   57.6    118.
##  3        66.5     59.8    -74.6     14.2      162.   57.6    118.
##  4        67       59.8    -74.6     14.2      162.   57.6    118.
##  5        67.5     59.8    -74.6     14.2      162.   57.6    118.
##  6        68       59.8    -74.6     14.2      162.   57.6    118.
##  7        68.5     93.3    -51.9     46.4      182.   73.5    129.
##  8        69      121.     -21.5     81.9      192.   83.0    136.
##  9        69.5    144.      15.6    117.       198.   90.1    141.
## 10        70      160.      54.4    149.       199.   96.6    142.
## # ℹ 50 more rows

Reordenar datos para grafica 3D

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_Manuel       59.8
##  2        65.5 d_Regina      -74.6
##  3        65.5 d_Marian       14.2
##  4        65.5 d_Ricardo     162. 
##  5        65.5 d_Neto         57.6
##  6        65.5 d_Johan       118. 
##  7        66   d_Manuel       59.8
##  8        66   d_Regina      -74.6
##  9        66   d_Marian       14.2
## 10        66   d_Ricardo     162. 
## # ℹ 350 more rows
#Grafica Derivadas

library(ggplot2)

grafica_derivadas <- ggplot(derivadas2, aes(x = Temperatura, 
                                            y = Derivadas, 
                                            color = Muestras)) +
  geom_line(size = 1.5) +
  theme_classic() +
  labs(
    title = "Curvas de derivada de disociación",
    subtitle = "Todas las muestras",
    caption = "Diseño: Ricardo Palos, Regina Hernández, Diego Campos",
    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(min(derivadas2$Temperatura),
                                  max(derivadas2$Temperatura),
                                  by = 2.5))

grafica_derivadas  

grafica_derivadas_3D<-plot_ly(derivadas2,
                              x= ~Temperatura,
                              y= ~Muestras,
                              z= ~Derivadas,
                              color= ~factor(Muestras),
                              type= "scatter3d",
                              mode= "lines",
                              lines= list(with=6)) %>% 
  layout(title = "Curvas de derivadas en 3D",
         scene = list(
           xaxis = list(title = "Temperatura (°C)"),
           yaxis = list(title = "Muestras"),
           zaxis = list(title = "-ΔT/ΔF")
         ))
grafica_derivadas_3D
## Warning: 'scatter3d' objects don't have these attributes: 'lines'
## Valid attributes include:
## 'connectgaps', 'customdata', 'customdatasrc', 'error_x', 'error_y', 'error_z', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'legendgroup', 'legendgrouptitle', 'legendrank', 'line', 'marker', 'meta', 'metasrc', 'mode', 'name', 'opacity', 'projection', 'scene', 'showlegend', 'stream', 'surfaceaxis', 'surfacecolor', 'text', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'visible', 'x', 'xcalendar', 'xhoverformat', 'xsrc', 'y', 'ycalendar', 'yhoverformat', 'ysrc', 'z', 'zcalendar', 'zhoverformat', 'zsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'scatter3d' objects don't have these attributes: 'lines'
## Valid attributes include:
## 'connectgaps', 'customdata', 'customdatasrc', 'error_x', 'error_y', 'error_z', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'legendgroup', 'legendgrouptitle', 'legendrank', 'line', 'marker', 'meta', 'metasrc', 'mode', 'name', 'opacity', 'projection', 'scene', 'showlegend', 'stream', 'surfaceaxis', 'surfacecolor', 'text', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'visible', 'x', 'xcalendar', 'xhoverformat', 'xsrc', 'y', 'ycalendar', 'yhoverformat', 'ysrc', 'z', 'zcalendar', 'zhoverformat', 'zsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'scatter3d' objects don't have these attributes: 'lines'
## Valid attributes include:
## 'connectgaps', 'customdata', 'customdatasrc', 'error_x', 'error_y', 'error_z', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'legendgroup', 'legendgrouptitle', 'legendrank', 'line', 'marker', 'meta', 'metasrc', 'mode', 'name', 'opacity', 'projection', 'scene', 'showlegend', 'stream', 'surfaceaxis', 'surfacecolor', 'text', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'visible', 'x', 'xcalendar', 'xhoverformat', 'xsrc', 'y', 'ycalendar', 'yhoverformat', 'ysrc', 'z', 'zcalendar', 'zhoverformat', 'zsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'scatter3d' objects don't have these attributes: 'lines'
## Valid attributes include:
## 'connectgaps', 'customdata', 'customdatasrc', 'error_x', 'error_y', 'error_z', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'legendgroup', 'legendgrouptitle', 'legendrank', 'line', 'marker', 'meta', 'metasrc', 'mode', 'name', 'opacity', 'projection', 'scene', 'showlegend', 'stream', 'surfaceaxis', 'surfacecolor', 'text', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'visible', 'x', 'xcalendar', 'xhoverformat', 'xsrc', 'y', 'ycalendar', 'yhoverformat', 'ysrc', 'z', 'zcalendar', 'zhoverformat', 'zsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'scatter3d' objects don't have these attributes: 'lines'
## Valid attributes include:
## 'connectgaps', 'customdata', 'customdatasrc', 'error_x', 'error_y', 'error_z', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'legendgroup', 'legendgrouptitle', 'legendrank', 'line', 'marker', 'meta', 'metasrc', 'mode', 'name', 'opacity', 'projection', 'scene', 'showlegend', 'stream', 'surfaceaxis', 'surfacecolor', 'text', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'visible', 'x', 'xcalendar', 'xhoverformat', 'xsrc', 'y', 'ycalendar', 'yhoverformat', 'ysrc', 'z', 'zcalendar', 'zhoverformat', 'zsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'scatter3d' objects don't have these attributes: 'lines'
## Valid attributes include:
## 'connectgaps', 'customdata', 'customdatasrc', 'error_x', 'error_y', 'error_z', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'legendgroup', 'legendgrouptitle', 'legendrank', 'line', 'marker', 'meta', 'metasrc', 'mode', 'name', 'opacity', 'projection', 'scene', 'showlegend', 'stream', 'surfaceaxis', 'surfacecolor', 'text', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'visible', 'x', 'xcalendar', 'xhoverformat', 'xsrc', 'y', 'ycalendar', 'yhoverformat', 'ysrc', 'z', 'zcalendar', 'zhoverformat', 'zsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'

Gráfica derivada equipo

grafica_derivada_equipo <- ggplot(derivadas,
                                  aes(x=Temperatura))+
  geom_line(aes(y=d_Ricardo, color = "d_Ricardo"), linewidth = 1.5)+
  scale_color_manual(values = c("d_Ricardo"="#0006b1"))+
  theme_classic()+
  labs(title = "Derviadas de disociacion",
       subtitle = "Tejido: Hígado",
       caption = "Diseño por: Campos, Hernandez, Palos",
       x = "Temperatura",
       y = expression(-Delta~F / Delta~T))+
  theme(
    axis.line = element_line(size = 1, 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.5))

grafica_derivada_equipo

Pico <-  max(derivadas$d_Ricardo)
Pico
## [1] 444.5493
#Temperatura
Tm <- derivadas %>% 
  filter(d_Ricardo == Pico) %>% 
  select(Temperatura, d_Ricardo)

Tm
## # A tibble: 1 × 2
##   Temperatura d_Ricardo
##         <dbl>     <dbl>
## 1        82.5      445.
#Grafica con etiqueta
grafica_derivada_equipo2 <- grafica_derivada_equipo+
  geom_vline(xintercept = Tm$Temperatura,
             color = "#880808",
             linetype = "dashed", 
             linewidth = 0.9)+
  geom_label_repel(data=Tm,
                   aes(x=Temperatura,
                       y=d_Ricardo,
                       label = paste("Tm = ", round(Temperatura), " °C")),
                   nudge_x = 4,
                   nudge_y = -0.9,
                   max.overlaps = 100,
                   color = "gray",
                   fill = "#900C3F")

grafica_derivada_equipo2