#Cmd´+opt+I - Chunk

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

Llamar paqueteria necesaria

install.packages("BiocManager")   # Instala BiocManager
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.5'
## (as 'lib' is unspecified)
install.packages("ggplot2")       # Instala ggplot2
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.5'
## (as 'lib' is unspecified)
library(BiocManager)
library(ggplot2)

# O con pacman:
pacman::p_load("vroom", "dplyr", "ggplot2", "tidyr")
Curvas_amplif <- vroom(file = "https://raw.githubusercontent.com/ManuelLaraMVZ/resultados_PCR_practica/refs/heads/main/Ejemplo_amplificacion_RT-PCR.csv")
## `curl` package not installed, falling back to using `url()`
## 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_amplif
## # A tibble: 35 × 6
##    Cycle         A1         B1         C1        D1         E1
##    <dbl>      <dbl>      <dbl>      <dbl>     <dbl>      <dbl>
##  1     1  0.0000213 -0.00531    0.0000279  0.000519  0.000468 
##  2     2 -0.0000305 -0.00286    0.00179    0.000301  0.000462 
##  3     3 -0.0000823 -0.00136   -0.000335   0.000842  0.0000266
##  4     4 -0.0000536 -0.00101    0.00166    0.000522 -0.000943 
##  5     5 -0.0000565 -0.000787   0.000199   0.000586  0.0000877
##  6     6  0.000111  -0.000233   0.00231    0.000451  0.00076  
##  7     7  0.000096   0.0000674 -0.000511  -0.00112  -0.000618 
##  8     8  0.0000698  0.000602  -0.000595  -0.000944  0.00108  
##  9     9  0.000202   0.00143    0.000166   0.000342 -0.000105 
## 10    10 -0.00001    0.00101   -0.00136   -0.000254  0.00102  
## # ℹ 25 more rows

Modificar base de datos

Curvas_amplif2 <- Curvas_amplif %>% 
  mutate(Ciclos = Cycle, H2O = A1, JRWF = B1, PPOF = C1, JTT = D1, DDR = E1) %>% select(-Cycle:-E1)
Curvas_amplif2
## # A tibble: 35 × 6
##    Ciclos        H2O       JRWF       PPOF       JTT        DDR
##     <dbl>      <dbl>      <dbl>      <dbl>     <dbl>      <dbl>
##  1      1  0.0000213 -0.00531    0.0000279  0.000519  0.000468 
##  2      2 -0.0000305 -0.00286    0.00179    0.000301  0.000462 
##  3      3 -0.0000823 -0.00136   -0.000335   0.000842  0.0000266
##  4      4 -0.0000536 -0.00101    0.00166    0.000522 -0.000943 
##  5      5 -0.0000565 -0.000787   0.000199   0.000586  0.0000877
##  6      6  0.000111  -0.000233   0.00231    0.000451  0.00076  
##  7      7  0.000096   0.0000674 -0.000511  -0.00112  -0.000618 
##  8      8  0.0000698  0.000602  -0.000595  -0.000944  0.00108  
##  9      9  0.000202   0.00143    0.000166   0.000342 -0.000105 
## 10     10 -0.00001    0.00101   -0.00136   -0.000254  0.00102  
## # ℹ 25 more rows

Reordenamiento de datos

  1. Seleccionar los datos a reordenar (variables dependientes)
  2. Agrupar por nombre
  3. Por ciclo
Curvas_amplif3 <- Curvas_amplif2 %>% 
  pivot_longer(cols = -Ciclos,
               names_to = "Muestras",
               values_to = "Fluoresencias")
Curvas_amplif3
## # A tibble: 175 × 3
##    Ciclos Muestras Fluoresencias
##     <dbl> <chr>            <dbl>
##  1      1 H2O          0.0000213
##  2      1 JRWF        -0.00531  
##  3      1 PPOF         0.0000279
##  4      1 JTT          0.000519 
##  5      1 DDR          0.000468 
##  6      2 H2O         -0.0000305
##  7      2 JRWF        -0.00286  
##  8      2 PPOF         0.00179  
##  9      2 JTT          0.000301 
## 10      2 DDR          0.000462 
## # ℹ 165 more rows

Gráfica

Grafica_amplif <- ggplot(data = Curvas_amplif3, mapping = aes (x = Ciclos, y = Fluoresencias, color = Muestras)) + 
  geom_line (linewith = 1.5)
## Warning in geom_line(linewith = 1.5): Ignoring unknown parameters: `linewith`
Grafica_amplif

Mejorar la gráfica

Umbral_ciclos <- 0.008
Grafica_amplif <- Grafica_amplif+
  geom_hline(yintercept = Umbral_ciclos, linetype = "dashed", color = "#A85994")+
  theme_classic()+
  labs(title = "Curvas de amplificación RT-qPCR",
       subtitle = "Todas las muestras",
       caption = "Diseño: Julieta Tavera",
       x = "Ciclos",
       y = "Fluoresencia (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"))+
  scale_x_continuous(breaks = seq(min(Curvas_amplif3$Ciclos),
                                  max(Curvas_amplif3$Ciclos),
                                  by = 2))+
  scale_y_continuous(breaks = seq(min(Curvas_amplif3$Fluoresencias),
                     max(Curvas_amplif3$Fluoresencias),
                     by = 0.02),
labels = scales:: number_format(accuracy = 0.05))
## 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 per session.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
Grafica_amplif

Grafica_amplif_equipo <- ggplot(Curvas_amplif2, aes(x = Ciclos)) +
  geom_line(aes(y = JTT, color = "JTT"), linewidth = 1.5) +
  geom_line(aes(y = H2O, color = "H2O"), linewidth = 1.5) +
  geom_hline(yintercept = Umbral_ciclos, linetype = "dashed", color = "#F54927") + 
  scale_color_manual(values = c("JTT" = "#EDB8AD", "H2O" = "#ADE9ED")) +
  theme_classic() +
  labs(title = "Curvas de amplificación RT-qPCR",
       subtitle = "Todas las muestras",
       caption = "Diseño: Julieta Tavera Tello",
       x = "Ciclos",
       y = "Fluorescencia (u.a.)",
       color = "Muestras") +
  theme(axis.line = element_line(linewidth = 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(Curvas_amplif2$Ciclos),
                                  max(Curvas_amplif2$Ciclos),
                                  by = 2)) +
  scale_y_continuous(breaks = seq(min(Curvas_amplif2$JTT),
                                  max(Curvas_amplif2$JTT),
                                  by = 0.02),
                     labels = scales::number_format(accuracy = 0.02))

Grafica_amplif_equipo