if(!require("pacman"))
  install.packages("pacman")
## Cargando paquete requerido: pacman
## Warning: package 'pacman' was built under R version 4.5.2
if(!require("tidyr"))
  install.packages("tidyr")
## Cargando paquete requerido: tidyr
library("pacman")
p_load("ggplot2",  
       "dplyr",
       "vroom")
Datos_PCR3 <- vroom(file="https://raw.githubusercontent.com/ManuelLaraMVZ/resultados_PCR_practica/refs/heads/main/Ejemplo_amplificacion_RT-PCR.csv")
## Rows: 35 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (6): Cycle, A1, B1, C1, D1, E1
## 
## ℹ 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.
Curvas_PCR <- Datos_PCR3 %>% 
  mutate(Ciclos = Cycle, H2O = A1, JRWF = B1, PPDF = C1, MLL = D1, DDR = E1) %>% 
  select(-Cycle:-E1) %>% 
  filter(Ciclos >= 17)
Curvas_PCR
## # A tibble: 19 × 6
##    Ciclos        H2O       JRWF      PPDF       MLL       DDR
##     <dbl>      <dbl>      <dbl>     <dbl>     <dbl>     <dbl>
##  1     17  0.0000132  0.00126   -0.00121   0.000599  0.000786
##  2     18  0.0000394  0.000431  -0.000969 -0.00155  -0.00119 
##  3     19 -0.000106   0.000227  -0.00145  -0.000874 -0.00113 
##  4     20 -0.000104   0.000133  -0.00197  -0.000632 -0.00134 
##  5     21 -0.000119   0.00104    0.000464  0.000245 -0.000417
##  6     22 -0.0000153  0.00028    0.0032   -0.00081   0.00158 
##  7     23  0.0000704 -0.000086   0.00494   0.00162   0.000497
##  8     24  0.00012   -0.000238   0.0144    0.00139   0.00121 
##  9     25 -0.0000899 -0.000484   0.0263    0.00634   0.00425 
## 10     26  0.0000114 -0.00133    0.0491    0.0101    0.00894 
## 11     27 -0.000104  -0.000824   0.0763    0.0202    0.0202  
## 12     28 -0.000101  -0.000922   0.105     0.0365    0.0353  
## 13     29 -0.000222  -0.000938   0.134     0.0624    0.0594  
## 14     30 -0.0000675 -0.000187   0.162     0.0895    0.0823  
## 15     31 -0.000089  -0.0000371  0.191     0.114     0.107   
## 16     32 -0.000188   0.0018     0.220     0.141     0.128   
## 17     33 -0.0000273  0.00345    0.243     0.170     0.152   
## 18     34  0.000358   0.00615    0.268     0.197     0.173   
## 19     35  0.000345   0.00913    0.293     0.223     0.192
Curvas_PCR2 <- Curvas_PCR %>% 
  pivot_longer(cols=-Ciclos,
               names_to="muestras",
               values_to="Fluorescencias")
Curvas_PCR2
## # A tibble: 95 × 3
##    Ciclos muestras Fluorescencias
##     <dbl> <chr>             <dbl>
##  1     17 H2O           0.0000132
##  2     17 JRWF          0.00126  
##  3     17 PPDF         -0.00121  
##  4     17 MLL           0.000599 
##  5     17 DDR           0.000786 
##  6     18 H2O           0.0000394
##  7     18 JRWF          0.000431 
##  8     18 PPDF         -0.000969 
##  9     18 MLL          -0.00155  
## 10     18 DDR          -0.00119  
## # ℹ 85 more rows
Graficas_PCR <- ggplot(Curvas_PCR2,
                       mapping = aes(x = Ciclos,
                                     y = Fluorescencias, 
                                     color = muestras)) +
  geom_line(linewidth = 1.5)

Graficas_PCR

umbral_ciclos <- 0.008

Graficas_PCR2 <- Graficas_PCR +
  geom_hline(yintercept = umbral_ciclos, linetype = "dashed", color = "#5286d0")+
  theme_classic()+
  labs(title = "Curvas de Amplificacion RT-qPCR",
       subtitle = "Todas las muestras",
       caption = "Diseño: Juana Rosetti",
       x = "Ciclos",
       y = "Fluorescencias(u.a.)")+
  theme(axis.line = element_line(size = 1.2, color="#c0b5e3"),
        axis.title = element_text(face = "bold"),
        axis.text = element_text(face = "bold"),
        legend.title = element_text(face = "bold"))+
  scale_x_continuous(breaks = seq(min(Curvas_PCR2$Ciclos),
                                  max(Curvas_PCR2$Ciclos),
                                  by = 2))+
  scale_y_continuous(breaks = seq(min(Curvas_PCR2$Fluorescencias),
                         max(Curvas_PCR2$Fluorescencias),
                         by = 0.02),
                     labels = scales::number_format(accuracy = 0.02))
## 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.
Graficas_PCR2

Grafica_PCR3 <- ggplot(Curvas_PCR,
                       aes(x = Ciclos, 
                           y = MLL)) +
  geom_line(linewidth = 1.2, color = "#ffb867")+
  geom_hline(yintercept = umbral_ciclos, linetype = "dashed", color = "#5286d0")+
  theme_classic()+
  labs(title = "Curvas de Amplificacion RT-qPCR",
       subtitle = "Todas las muestras",
       caption = "Diseño: Juana Rosetti",
       x = "Ciclos",
       y = "Fluorescencias(u.a.)")+
  theme(axis.line = element_line(size = 1.2, color="#c0b5e3"),
        axis.title = element_text(face = "bold"),
        axis.text = element_text(face = "bold"),
        legend.title = element_text(face = "bold"))+
  scale_x_continuous(breaks = seq(min(Curvas_PCR2$Ciclos),
                                  max(Curvas_PCR2$Ciclos),
                                  by = 2))+
  scale_y_continuous(breaks = seq(min(Curvas_PCR$MLL),
                         max(Curvas_PCR$MLL),
                         by = 0.02),
                     labels = scales::number_format(accuracy = 0.02))+
  geom_line(aes(x = Ciclos, 
                y = H2O),
            color = "#fc77c0",
            linewidth = 1.5)

Grafica_PCR3

Grafica_PCR4 <- ggplot(Curvas_PCR,
                       aes(x = Ciclos)) +
  geom_line(aes(y = MLL), color = "#ffb867", linewidth = 1.5)+
  geom_line(aes(y = H2O), color = "#fc77c0", linewidth = 1.5)+
  geom_hline(yintercept = umbral_ciclos, linetype = "dashed", color = "#5286d0")+
  theme_classic()+
  labs(title = "Curvas de Amplificacion RT-qPCR",
       subtitle = "MLL (naranja) y H2O (rosa)",
       caption = "Diseño: Juana Rosetti",
       x = "Ciclos",
       y = "Fluorescencias(u.a.)")+
  theme(axis.line = element_line(size = 1.2, color="#c0b5e3"),
        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(Curvas_PCR$Ciclos),
                                  max(Curvas_PCR$Ciclos),
                                  by = 2))+
  scale_y_continuous(breaks = seq(min(Curvas_PCR$MLL),
                         max(Curvas_PCR$MLL),
                         by = 0.02),
                     labels = scales::number_format(accuracy = 0.02))

Grafica_PCR4