Cargando paquete requerido: ggpp
Registered S3 methods overwritten by 'ggpp':
method from
heightDetails.titleGrob ggplot2
widthDetails.titleGrob ggplot2
Adjuntando el paquete: 'ggpp'
The following object is masked from 'package:ggplot2':
annotate
Adjuntando el paquete: 'ggpubr'
The following objects are masked from 'package:ggpp':
as_npc, as_npcx, as_npcy
The following object is masked from 'package:egg':
ggarrange
# Calcular el número de observaciones por grupoobservaciones <- dat %>%group_by(group) %>%summarise(n =n())# Crear el gráfico de densidad con facetas y añadir número de observaciones y cardúmenesggplot(dat) +geom_density(alpha =1, size =0.75, aes(fill = group, x = Value)) +theme_presentation(base_size =16) +facet_wrap(facets ="group", ncol =3, strip.position ="top") +coord_cartesian(expand =FALSE)
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
Warning: Removed 19303 rows containing non-finite outside the scale range
(`stat_density()`).
geom_text(data = observaciones, aes(label =paste("n =", n)),x =Inf, y =-Inf, hjust =1, vjust =0, size =5, color ="black")
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
ggplotly(plot_gg, tooltip =c("Detect_school"))
# Calcular el número de observaciones por grupoobservaciones <- dat_filter_one_by_one %>%group_by(group) %>%summarise(n =n())# Crear el gráfico de densidad con facetas y añadir número de observacionesggplot(dat_filter_one_by_one) +geom_density(alpha =1, size =0.75, aes(fill = group, x = Value)) +theme_presentation(base_size =24) +# Cambiado a theme_minimal para simplificarfacet_wrap(facets ="group", ncol =1, strip.position ="right") +coord_cartesian(expand = F) +geom_label(data = observaciones, aes(label =paste("n =", n)),x =Inf, y =-Inf, hjust =2, vjust =-1, size =5, fill ="white", color ="black")
Limpieza de datos sobre Sv
Z-score Modificado
# Definir función para filtrar valores atípicos por grupo usando Z-Score modificadofilter_outliers_modified_zscore <-function(data, group_var, value_var, threshold =3.5) { data %>%group_by({{group_var}}) %>%mutate(median_value =median({{value_var}}, na.rm =TRUE),mad_value =mad({{value_var}}, constant =1, na.rm =TRUE),modified_z_score =abs({{value_var}} - median_value) / (mad_value *1.4826)) %>%filter(modified_z_score <= threshold) %>%select(-median_value, -mad_value, -modified_z_score)}# Aplicar la función para filtrar valores atípicos por grupo usando Z-Score modificadodat_clean_modified_zscore <- dat_filter_one_by_one %>%filter_outliers_modified_zscore(group, Value, threshold =3.5)
Box plot
dat_clean_modified_z-score
library(ggplot2)Figura01=ggplot(dat_clean_modified_zscore)+geom_boxplot(alpha=0.5,size=0.75, aes(fill=group,y = Value, x=group), show.legend = F)+theme_presentation(base_size =15) +ylab("Sv (dB)")+#Average response#scale_fill_brewer(palette = "RdYlBu",name="Especie")+#scale_fill_viridis_d(option = "C")+scale_fill_manual(name="Anchoveta",values =c("#5f5f5f","#0000ff","#000080","#00bf00","#ffff00","#ff8000","#ff00bf","#ff0000","#a6533c"))+scale_x_discrete(name ="Longitud (cm)", labels =c("3.5","4","5","7.5","10.5","11","12","12.5","13.5"))+theme(legend.position ="top")+#legend.title=element_blank()#scale_x_discrete(name = "Bandas (kHz)")+theme(panel.grid.major.y =element_line(color ="gray", linetype ="dashed"))Figura02=ggplot(dat_clean_modified_zscore)+geom_boxplot(alpha=0.5,size=0.75, aes(fill=group,y = Value, x=group), show.legend = F)+theme_presentation(base_size =12) +ylab("Sv (dB)")+#Average response#scale_fill_brewer(palette = "RdYlBu",name="Especie")+#scale_fill_viridis_d(option = "C")+scale_fill_manual(name="Anchoveta",values =c("#5f5f5f","#0000ff","#000080","#00bf00","#ffff00","#ff8000","#ff00bf","#ff0000","#a6533c"))+scale_x_discrete(name ="Longitud (cm)", labels =c("3.5","4","5","7.5","10.5","11","12","12.5","13.5"))+theme(legend.position ="top")+#legend.title=element_blank()#scale_x_discrete(name = "Bandas (kHz)")+theme(panel.grid.major.y =element_line(color ="gray", linetype ="dashed"))+facet_wrap(~Banda)ggsave(filename ="Boxplot_FM_global_modas.png",plot = Figura01, height =5, # Specifies the height of the plot in incheswidth =6, # Specifies the width of the plot in inchesdpi =1000, # Specifies the resolution in dots per inchpath ="F:/Tesis abordo/Tesis abordo/Figuras/Objetivo02/",device ="png") ggsave(filename ="Boxplot_FM_modas.png",plot = Figura02, height =5, # Specifies the height of the plot in incheswidth =6, # Specifies the width of the plot in inchesdpi =1000, # Specifies the resolution in dots per inchpath ="F:/Tesis abordo/Tesis abordo/Figuras/Objetivo02/",device ="png")