Tallas Quarto

Author

Luis La Cruz

Tallas

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

Datos

When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

1 + 1
[1] 2

You can add options to executable code like this

[1] 4

The echo: false option disables the printing of code (only output is displayed).

#setwd("C:/Users/luis.lacruz/Music/Tesis abordo")
dir()
  [1] "~$DACCIÓN de Tesis_Luis La Cruz_y_German Chacón VER.10JUL2023.docx"                        
  [2] "~$DACCIÓN de Tesis_Luis La Cruz_y_German Chacón VER.DIC2023 - copia_parte 22222222222.docx"
  [3] "~$DACCIÓN de Tesis_Luis La Cruz_y_German Chacón VER.DIC2023.docx"                          
  [4] "000018.png"                                                                                
  [5] "1.-Datos-y-limpieza_Objetivo_2_files"                                                      
  [6] "1. Datos y limpieza.qmd"                                                                   
  [7] "1. Datos y limpieza_Objetivo_1.qmd"                                                        
  [8] "1. Datos y limpieza_Objetivo_2.html"                                                       
  [9] "1. Datos y limpieza_Objetivo_2.qmd"                                                        
 [10] "1. Datos y limpieza_Objetivo_2_files"                                                      
 [11] "2.-Prueba-de-normalidad_Objetivo__1_files"                                                 
 [12] "2.-Prueba-de-normalidad_Objetivo_1.rmarkdown"                                              
 [13] "2.-Prueba-de-normalidad_Objetivo_2_files"                                                  
 [14] "2. Prueba de normalidad.qmd"                                                               
 [15] "2. Prueba de normalidad_Objetivo__1.html"                                                  
 [16] "2. Prueba de normalidad_Objetivo__1.qmd"                                                   
 [17] "2. Prueba de normalidad_Objetivo__1_files"                                                 
 [18] "2. Prueba de normalidad_Objetivo_2.html"                                                   
 [19] "2. Prueba de normalidad_Objetivo_2.qmd"                                                    
 [20] "2. Prueba de normalidad_Objetivo_2_files"                                                  
 [21] "3.-Estadística-descriptiva_Objetivo_2_files"                                               
 [22] "3.-Estadística-descriptiva_Objetivo01_puedeSER.rmarkdown"                                  
 [23] "3.-Estadística-descriptiva_Objetivo01_puedeSER_files"                                      
 [24] "3. Estadística descriptiva.qmd"                                                            
 [25] "3. Estadística descriptiva_Objetivo_2.html"                                                
 [26] "3. Estadística descriptiva_Objetivo_2.qmd"                                                 
 [27] "3. Estadística descriptiva_Objetivo_2_files"                                               
 [28] "3. Estadística descriptiva_Objetivo01_puedeSER.html"                                       
 [29] "3. Estadística descriptiva_Objetivo01_puedeSER.qmd"                                        
 [30] "3. Estadística descriptiva_Objetivo01_puedeSER.rmarkdown"                                  
 [31] "3. Estadística descriptiva_Objetivo01_puedeSER_files"                                      
 [32] "3_Estadística descriptiva_Objetivo_1.qmd"                                                  
 [33] "4.-Ancova-lineal_objetivo_1_files"                                                         
 [34] "4.-Ancova-lineal_Objetivo_2_files"                                                         
 [35] "4. Ancova lineal.qmd"                                                                      
 [36] "4. Ancova lineal_objetivo_1.html"                                                          
 [37] "4. Ancova lineal_objetivo_1.qmd"                                                           
 [38] "4. Ancova lineal_objetivo_1_files"                                                         
 [39] "4. Ancova lineal_Objetivo_2.html"                                                          
 [40] "4. Ancova lineal_Objetivo_2.qmd"                                                           
 [41] "4. Ancova lineal_Objetivo_2_files"                                                         
 [42] "4. Ancova.qmd"                                                                             
 [43] "5.-Segmentación-objetivo1.rmarkdown"                                                       
 [44] "5.-Segmentación-objetivo1_files"                                                           
 [45] "5.-Segmentación_Objetivo_2_files"                                                          
 [46] "5. Segmentación objetivo1.html"                                                            
 [47] "5. Segmentación objetivo1.qmd"                                                             
 [48] "5. Segmentación objetivo1.rmarkdown"                                                       
 [49] "5. Segmentación objetivo1_files"                                                           
 [50] "5. Segmentación.qmd"                                                                       
 [51] "5. Segmentación_Objetivo_2.html"                                                           
 [52] "5. Segmentación_Objetivo_2.qmd"                                                            
 [53] "5. Segmentación_Objetivo_2_files"                                                          
 [54] "Analisis-FM-Especies_files"                                                                
 [55] "Analisis-FM_Tesis_Enero_2024.html"                                                         
 [56] "Analisis-FM_Tesis_Enero_2024.Rmd"                                                          
 [57] "Analisis-FM_Tesis_Junio_2023.html"                                                         
 [58] "Analisis FM Especies.html"                                                                 
 [59] "Analisis FM Especies.qmd"                                                                  
 [60] "Analisis FM Especies_files"                                                                
 [61] "Analisis_FM_Tesis_Junio_2023_files"                                                        
 [62] "Anchoverso-modal_files"                                                                    
 [63] "Anchoverso modal.qmd"                                                                      
 [64] "Anchoverso_modal_Marzo_2024.html"                                                          
 [65] "Anchoverso_modal_Marzo_2024.qmd"                                                           
 [66] "Anchoverso_modal_Marzo_2024_files"                                                         
 [67] "Barras_Lances_FM.tiff"                                                                     
 [68] "Base_generada_para_RF_respaldo.csv"                                                        
 [69] "Base_generada_para_RF_respaldo_01ENERO2024.csv"                                            
 [70] "box plot especies.tiff"                                                                    
 [71] "box plot especies_sv.tiff"                                                                 
 [72] "dat.csv"                                                                                   
 [73] "dat_clean_modified_zscore_anchoveta.csv"                                                   
 [74] "dat_clean_modified_zscore_especies.csv"                                                    
 [75] "dat_clean_std_anchoveta.csv"                                                               
 [76] "dat_clean_sv_anchoveta.csv"                                                                
 [77] "dat2.csv"                                                                                  
 [78] "Datos original TOTAL_clasificacion RF_probabilidad de clasificacion.csv"                   
 [79] "Datos_FM_Tesis.xlsx"                                                                       
 [80] "Datos_FM_Tesis_moda - copia.xlsx"                                                          
 [81] "Datos_FM_Tesis_moda.xlsx"                                                                  
 [82] "descriptiva_clean_Sv.csv"                                                                  
 [83] "descriptiva_clean_Sv_lineal.csv"                                                           
 [84] "descriptiva_clean_Sv_por banda.csv"                                                        
 [85] "Exploración FM-20231127T002638Z-001"                                                       
 [86] "Figura 1_Sv_std.tiff"                                                                      
 [87] "Figura 2_Sv_depth.tiff"                                                                    
 [88] "Figura 3_Sv_std.tiff"                                                                      
 [89] "Figuras"                                                                                   
 [90] "firmas especies_std_lm.tiff"                                                               
 [91] "firmas especies_sv_gam.tiff"                                                               
 [92] "firmas especies_sv_lm.tiff"                                                                
 [93] "FR.qmd"                                                                                    
 [94] "Lances_FM.tiff"                                                                            
 [95] "last"                                                                                      
 [96] "mc.tiff"                                                                                   
 [97] "Metadata_FM_Tesis.xlsx"                                                                    
 [98] "Prueba K-S entre grupos de tallas.csv"                                                     
 [99] "prueba.csv"                                                                                
[100] "prueba2.csv"                                                                               
[101] "prueba2.xlsx"                                                                              
[102] "REDACCIÓN de Tesis_Luis La Cruz_y_German Chacón VER.DIC2023 - copia.docx"                  
[103] "REDACCIÓN de Tesis_Luis La Cruz_y_German Chacón VER.DIC2023 - copia_parte 22222222222.docx"
[104] "REDACCIÓN de Tesis_Luis La Cruz_y_German Chacón VER.DIC2023.docx"                          
[105] "resumen descriptivo.csv"                                                                   
[106] "RF-Clases-anchoveta_files"                                                                 
[107] "RF-Clases_files"                                                                           
[108] "RF Clases anchoveta basado solo en frecuencias.qmd"                                        
[109] "RF Clases anchoveta.html"                                                                  
[110] "RF Clases anchoveta_files"                                                                 
[111] "RF Clases.html"                                                                            
[112] "RF Clases_files"                                                                           
[113] "rsconnect"                                                                                 
[114] "salida.csv"                                                                                
[115] "Std_anc_vin.tiff"                                                                          
[116] "subset_FM.csv"                                                                             
[117] "Sv_species.tiff"                                                                           
[118] "Tallas.html"                                                                               
[119] "Tallas.png"                                                                                
[120] "Tallas.qmd"                                                                                
[121] "Tallas.rmarkdown"                                                                          
[122] "Tallas.tiff"                                                                               
[123] "Tallas_files"                                                                              
[124] "Tallas2222.png"                                                                            
[125] "Tesis.docx"                                                                                
[126] "Tesis.pdf"                                                                                 
[127] "Tesis.qmd"                                                                                 
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(gridExtra)

Adjuntando el paquete: 'gridExtra'

The following object is masked from 'package:dplyr':

    combine
library(ggplot2)
library(readxl)
library(tidyverse)
datos_talla=read_excel("Metadata_FM_Tesis.xlsx", sheet="Tallas")

datos_talla 
# A tibble: 14 × 40
   N_Catch_Year `1`   `1.5` `2`   `2.5`   `3` `3.5`   `4` `4.5`   `5` `5.5`
   <chr>        <lgl> <lgl> <lgl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
 1 L18_A18      NA    NA    NA       NA    NA    NA    NA    NA    NA    NA
 2 L12_A18      NA    NA    NA       NA    NA    NA    NA    NA    NA    NA
 3 L19_A18      NA    NA    NA       NA    NA    NA    NA    NA    NA    NA
 4 L22_A18      NA    NA    NA       NA    NA    NA    NA    NA    NA    NA
 5 L33_A18      NA    NA    NA       NA    NA    NA    NA    NA    NA    NA
 6 L74_A18      NA    NA    NA        2    32   124    11    NA    NA    NA
 7 L78_A18      NA    NA    NA       NA    93   118    17    NA    NA    NA
 8 L12_A21      NA    NA    NA       NA    NA    NA    NA    NA    NA    NA
 9 L19_A21      NA    NA    NA       NA    NA    NA    NA    NA    NA    NA
10 L28_A21      NA    NA    NA       NA    NA    NA    NA    NA    NA    NA
11 L36_A21      NA    NA    NA       NA    NA    NA    NA    NA    NA    NA
12 L56_A21      NA    NA    NA       NA    NA    NA    NA    NA    NA    NA
13 L76_A21      NA    NA    NA       NA    NA    NA    NA    NA    NA    NA
14 L106_A21     NA    NA    NA       NA    NA     1     7     7     7     1
# ℹ 29 more variables: `6` <dbl>, `6.5` <dbl>, `7` <lgl>, `7.5` <lgl>,
#   `8` <lgl>, `8.5` <dbl>, `9` <dbl>, `9.5` <dbl>, `10` <dbl>, `10.5` <dbl>,
#   `11` <dbl>, `11.5` <dbl>, `12` <dbl>, `12.5` <dbl>, `13` <dbl>,
#   `13.5` <dbl>, `14` <dbl>, `14.5` <dbl>, `15` <dbl>, `15.5` <dbl>,
#   `16` <dbl>, `16.5` <dbl>, `17` <lgl>, `17.5` <lgl>, `18` <lgl>,
#   `18.5` <lgl>, `19` <lgl>, `19.5` <lgl>, `20` <lgl>
datos_talla_longer= datos_talla  %>%
  pivot_longer(!N_Catch_Year, names_to = "Length", values_to = "count",
    values_drop_na = TRUE)

datos_talla_longer
# A tibble: 130 × 3
   N_Catch_Year Length count
   <chr>        <chr>  <dbl>
 1 L18_A18      8.5        8
 2 L18_A18      9         52
 3 L18_A18      9.5       84
 4 L18_A18      10        85
 5 L18_A18      10.5     126
 6 L18_A18      11        87
 7 L18_A18      11.5      68
 8 L18_A18      12        39
 9 L18_A18      12.5      15
10 L18_A18      13        13
# ℹ 120 more rows
library(dplyr)


datos_talla_longer_freq= datos_talla_longer %>%
  group_by(
N_Catch_Year) %>%
  mutate(freq = count / sum(count))

datos_talla_longer_freq
# A tibble: 130 × 4
# Groups:   N_Catch_Year [14]
   N_Catch_Year Length count   freq
   <chr>        <chr>  <dbl>  <dbl>
 1 L18_A18      8.5        8 0.0136
 2 L18_A18      9         52 0.0883
 3 L18_A18      9.5       84 0.143 
 4 L18_A18      10        85 0.144 
 5 L18_A18      10.5     126 0.214 
 6 L18_A18      11        87 0.148 
 7 L18_A18      11.5      68 0.115 
 8 L18_A18      12        39 0.0662
 9 L18_A18      12.5      15 0.0255
10 L18_A18      13        13 0.0221
# ℹ 120 more rows
datos_talla_longer_freq$Composicion_tallas=cut(as.numeric(datos_talla_longer_freq$Length), breaks=c(0,3.5,5,11.5,16),
  include.lowest=F, right=T,labels=c("2-3.5","4-5","5.5-11.5","12-16.5"))

# datos_talla_longer_freq$Composicion_tallas=cut(as.numeric(datos_talla_longer_freq$Length), breaks=c(0,4.5,8,11.5,14.5,20),
#   include.lowest=F, right=T,labels=c("2-4.5","5-8","8.5-11.5","12-14.5","15-20"))

tabla_composicion_tallas=table(datos_talla_longer_freq$Composicion_tallas,datos_talla_longer_freq$N_Catch_Year)



tabla.prop_tabla_composicion_tallas=as.data.frame(prop.table(x=tabla_composicion_tallas, margin=2))
names(tabla.prop_tabla_composicion_tallas)=c("Longitud","Lance","Composicion")

tabla.prop_tabla_composicion_tallas$Composicion_porcentaje=tabla.prop_tabla_composicion_tallas$Composicion*100
tabla.prop_tabla_composicion_tallas
   Longitud    Lance Composicion Composicion_porcentaje
1     2-3.5 L106_A21   0.1428571               14.28571
2       4-5 L106_A21   0.4285714               42.85714
3  5.5-11.5 L106_A21   0.4285714               42.85714
4   12-16.5 L106_A21   0.0000000                0.00000
5     2-3.5  L12_A18   0.0000000                0.00000
6       4-5  L12_A18   0.0000000                0.00000
7  5.5-11.5  L12_A18   0.0000000                0.00000
8   12-16.5  L12_A18   1.0000000              100.00000
9     2-3.5  L12_A21   0.0000000                0.00000
10      4-5  L12_A21   0.0000000                0.00000
11 5.5-11.5  L12_A21   0.3076923               30.76923
12  12-16.5  L12_A21   0.6923077               69.23077
13    2-3.5  L18_A18   0.0000000                0.00000
14      4-5  L18_A18   0.0000000                0.00000
15 5.5-11.5  L18_A18   0.5000000               50.00000
16  12-16.5  L18_A18   0.5000000               50.00000
17    2-3.5  L19_A18   0.0000000                0.00000
18      4-5  L19_A18   0.0000000                0.00000
19 5.5-11.5  L19_A18   0.3076923               30.76923
20  12-16.5  L19_A18   0.6923077               69.23077
21    2-3.5  L19_A21   0.0000000                0.00000
22      4-5  L19_A21   0.0000000                0.00000
23 5.5-11.5  L19_A21   0.4166667               41.66667
24  12-16.5  L19_A21   0.5833333               58.33333
25    2-3.5  L22_A18   0.0000000                0.00000
26      4-5  L22_A18   0.0000000                0.00000
27 5.5-11.5  L22_A18   0.3571429               35.71429
28  12-16.5  L22_A18   0.6428571               64.28571
29    2-3.5  L28_A21   0.0000000                0.00000
30      4-5  L28_A21   0.0000000                0.00000
31 5.5-11.5  L28_A21   0.0000000                0.00000
32  12-16.5  L28_A21   1.0000000              100.00000
33    2-3.5  L33_A18   0.0000000                0.00000
34      4-5  L33_A18   0.0000000                0.00000
35 5.5-11.5  L33_A18   0.1111111               11.11111
36  12-16.5  L33_A18   0.8888889               88.88889
37    2-3.5  L36_A21   0.0000000                0.00000
38      4-5  L36_A21   0.0000000                0.00000
39 5.5-11.5  L36_A21   0.3846154               38.46154
40  12-16.5  L36_A21   0.6153846               61.53846
41    2-3.5  L56_A21   0.0000000                0.00000
42      4-5  L56_A21   0.0000000                0.00000
43 5.5-11.5  L56_A21   0.5454545               54.54545
44  12-16.5  L56_A21   0.4545455               45.45455
45    2-3.5  L74_A18   0.7500000               75.00000
46      4-5  L74_A18   0.2500000               25.00000
47 5.5-11.5  L74_A18   0.0000000                0.00000
48  12-16.5  L74_A18   0.0000000                0.00000
49    2-3.5  L76_A21   0.0000000                0.00000
50      4-5  L76_A21   0.0000000                0.00000
51 5.5-11.5  L76_A21   0.8000000               80.00000
52  12-16.5  L76_A21   0.2000000               20.00000
53    2-3.5  L78_A18   0.6666667               66.66667
54      4-5  L78_A18   0.3333333               33.33333
55 5.5-11.5  L78_A18   0.0000000                0.00000
56  12-16.5  L78_A18   0.0000000                0.00000
datos_talla_longer_freq
# A tibble: 130 × 5
# Groups:   N_Catch_Year [14]
   N_Catch_Year Length count   freq Composicion_tallas
   <chr>        <chr>  <dbl>  <dbl> <fct>             
 1 L18_A18      8.5        8 0.0136 5.5-11.5          
 2 L18_A18      9         52 0.0883 5.5-11.5          
 3 L18_A18      9.5       84 0.143  5.5-11.5          
 4 L18_A18      10        85 0.144  5.5-11.5          
 5 L18_A18      10.5     126 0.214  5.5-11.5          
 6 L18_A18      11        87 0.148  5.5-11.5          
 7 L18_A18      11.5      68 0.115  5.5-11.5          
 8 L18_A18      12        39 0.0662 12-16.5           
 9 L18_A18      12.5      15 0.0255 12-16.5           
10 L18_A18      13        13 0.0221 12-16.5           
# ℹ 120 more rows

Lances

library(egg)
library(envalysis)
library(dplyr)
p=ggplot(datos_talla_longer_freq)+
  geom_col(aes(as.numeric(Length),freq*100,fill=Composicion_tallas),alpha=0.5)+
  scale_x_continuous(name = "Longitud (cm)",breaks=c(2:20),labels = c("2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20"))+
  scale_y_continuous(name="Frecuencia (%)")+ #limits = c(0,50) 
  #scale_fill_viridis_d(option = "G")+
     #scale_fill_brewer(palette = "RdYlBu",name="Longitud(cm)")+
  #scale_color_manual(name="Longitud (cm)",values =c("royalblue1","orange","green3","darkorchid4"))+
  
        scale_fill_manual(name="Longitud (cm)",values =c("royalblue1","orange","green3","darkorchid4"))+
  #scale_fill_manual(values=c("red", "orange", "yellow", "blue", "navy"),name="Clase (cm)")+
  geom_vline(xintercept=12, color='black', size=0.5)+ #linetype='dashed'

   theme_presentation()+
    theme(legend.position = "none")
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
p

ggsave(filename = "Tallas_total.png",
  plot = p,     
  height = 10,             # Specifies the height of the plot in inches
       width = 25,              # Specifies the width of the plot in inches
       dpi = 1000,             # Specifies the resolution in dots per inch
       path = "F:/Tesis abordo/Tesis abordo/Figuras/Tallas/",device = "png") 
p2=ggplot(datos_talla_longer_freq)+
  geom_col(aes(as.numeric(Length),freq*100,fill=Composicion_tallas),alpha=0.5)+
  scale_x_continuous(name = "Longitud (cm)",breaks=c(2:20),labels = c("2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20"))+
  scale_y_continuous(name="Frecuencia (%)")+ #limits = c(0,50) 
  #scale_fill_viridis_d(option = "G")+
     #scale_fill_brewer(palette = "RdYlBu",name="Longitud(cm)")+
          scale_fill_manual(name="Longitud (cm)",values =c("royalblue1","orange","green3","darkorchid4"))+
  #scale_fill_manual(values=c("red", "orange", "yellow", "blue", "navy"),name="Clase (cm)")+
  geom_vline(xintercept=12, color='black', size=0.5)+ #linetype='dashed'

  
  facet_wrap(~N_Catch_Year,scales = "free_y",ncol = 2)+
    
   theme_presentation(base_size = 15)+
    theme(legend.position = "none")
p2

p2

ggsave(filename = "Tallas.png",
  plot = p2,     
  height = 10,             # Specifies the height of the plot in inches
       width = 8,              # Specifies the width of the plot in inches
       dpi = 1000,             # Specifies the resolution in dots per inch
       path = "F:/Tesis abordo/Tesis abordo/Figuras/Tallas/",device = "png") 

Composición

p3=Figura_clases=ggplot(tabla.prop_tabla_composicion_tallas)+
  geom_bar(aes(x=Lance, y=Composicion_porcentaje, fill=Longitud), stat="identity", width = 0.60, color="black",alpha=0.5)+
  #scale_fill_manual(values=c("red", "orange", "yellow", "blue", "navy"))+
       #scale_fill_brewer(palette = "RdYlBu",name="Longitud(cm)")+
            scale_fill_manual(name="Longitud (cm)",values =c("royalblue1","orange","green3","darkorchid4"))+
  labs(fill = "Longitud (cm)")+
  
  scale_y_continuous(name="Composicion (%)",limits = c(0,100))+
  scale_x_discrete(name="Lance")+
    theme_presentation(base_size = 10)+
  
  # theme(strip.text.y = element_blank() , strip.text.x = element_blank(),
  # strip.background = element_blank(),
  # plot.margin = unit( c(0,0,0,0) , units = "lines" ) )+
  # 
  # theme(plot.title = element_text(hjust = 0.5),
  #       axis.text.x=element_text(size=9, angle = 0, vjust = 0.5, hjust=0.5),
  #       axis.text.y=element_text(size=12),
  #       strip.text = element_text(size = 120))+
  # 
  # theme(axis.title.x = element_text(size = 12),
  #       axis.title.y = element_text(size = 12))+
  # 
    theme(legend.position = "top")
  # 
  # theme(legend.title = element_text(size=12),
  #       legend.text = element_text(size=12))+
  # 
  # theme(axis.title.y.right = element_text(color = "black"))+
  # theme(axis.title.y.left =element_text(color = "black"))

p3

p3

ggsave(filename = "Tallas_barras.png",
  plot = p3,     
  height = 4,             # Specifies the height of the plot in inches
       width = 8,              # Specifies the width of the plot in inches
       dpi = 1000,             # Specifies the resolution in dots per inch
       path = "F:/Tesis abordo/Tesis abordo/Figuras/Tallas/",device = "png") 

Referencias