##
## Adjuntando el paquete: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(gt)
library(magrittr)
Sedimentos_Marinos <- read.csv(
"ESTADISTICA/dataset_geologico_limpio_80.csv",
header = TRUE,
sep = ",",
dec = ".",
stringsAsFactors = FALSE
)#Limpieza y transformación de la variable DEPTH_M
Sedimentos_Marinos <- Sedimentos_Marinos %>%
mutate(
Profundidad_raw = DEPTH_M,
Profundidad_clean = as.numeric(gsub("[^0-9.-]", "", DEPTH_M))
) %>%
mutate(
Profundidad_cat = case_when(
is.na(Profundidad_clean) ~ NA_character_,
Profundidad_clean >= 0 & Profundidad_clean < 100 ~ "Poco profundo",
Profundidad_clean >= 100 & Profundidad_clean < 1000 ~ "Profundo",
Profundidad_clean >= 1000 ~ "Muy profundo",
TRUE ~ NA_character_
)
) %>%
mutate(
Profundidad_cat = factor(Profundidad_cat,
levels = c("Poco profundo", "Profundo", "Muy profundo"),
ordered = TRUE)
)
# Filtrar registros válidos
Sedimentos_Marinos_Prof <- Sedimentos_Marinos %>%
filter(!is.na(Profundidad_cat))TABLA DE DISTRIBUCIÓN DE FRECUENCIA
TDF_Prof_Final <- Sedimentos_Marinos_Prof %>%
count(Profundidad_cat, name = "ni") %>%
mutate(hi = round(ni / sum(ni) * 100, 2)) %>%
rename(Profundidad = Profundidad_cat) %>%
bind_rows(
data.frame(
Profundidad = "Total",
ni = sum(.$ni),
hi = 100
)
)
tabla_prof_gt <- TDF_Prof_Final %>%
gt() %>%
tab_header(
title = md("**Tabla N°1**"),
subtitle = md("Frecuencias Absolutas y Relativas según Rango de Profundidad")
) %>%
tab_source_note(source_note = md("Autor: Leonel Padilla")) %>%
tab_style(
style = cell_text(weight = "bold"),
locations = cells_body(rows = Profundidad == "Total")
)
tabla_prof_gt| Tabla N°1 | ||
| Frecuencias Absolutas y Relativas según Rango de Profundidad | ||
| Profundidad | ni | hi |
|---|---|---|
| Poco profundo | 18047 | 66.91 |
| Profundo | 6655 | 24.67 |
| Muy profundo | 2269 | 8.41 |
| Total | 26971 | 100.00 |
| Autor: Leonel Padilla | ||
TDF_Prof_Plot <- TDF_Prof_Final %>%
filter(Profundidad != "Total")
# Gráficas
barplot(TDF_Prof_Plot$ni,
main = "Gráfica Nº1: Frecuencia Local por Rango de Profundidad (ni)",
xlab = "Rango de Profundidad", ylab = "Cantidad",
col = "yellow", names.arg = TDF_Prof_Plot$Profundidad,
las = 2, cex.names = 0.85)barplot(TDF_Prof_Plot$ni,
main = "Gráfica Nº2: Frecuencia Global por Rango de Profundidad (ni)",
xlab = "Rango de Profundidad", ylab = "Cantidad",
col = "orange", names.arg = TDF_Prof_Plot$Profundidad,
las = 2, ylim = c(0, sum(TDF_Prof_Plot$ni)))barplot(TDF_Prof_Plot$hi,
main = "Gráfica Nº3: Frecuencia Relativa Local (hi %)",
xlab = "Rango de Profundidad", ylab = "Porcentaje (%)",
col = "cyan", names.arg = TDF_Prof_Plot$Profundidad, las = 2)barplot(TDF_Prof_Plot$hi,
main = "Gráfica Nº4: Frecuencia Relativa Global (hi %)",
xlab = "Rango de Profundidad", ylab = "Porcentaje (%)",
col = "#86D0B9", names.arg = TDF_Prof_Plot$Profundidad,
las = 2, ylim = c(0, 100))# Diagrama de circulo (Gráfica Nº5)
Colores <- c("#41B7C4", "#FECEA3", "#5182AF")
etiquetas <- paste0(round(TDF_Prof_Plot$hi), "%")
par(xpd = TRUE)
pie(TDF_Prof_Plot$hi, labels = etiquetas, col = Colores, radius = 0.85,
main = "Gráfica Nº5: Distribución Porcentual por Rango de Profundidad (%)")
legend("right", inset = -0.25, legend = TDF_Prof_Plot$Profundidad,
fill = Colores, cex = 0.8, bty = "n")tabla_freq_prof <- table(Sedimentos_Marinos_Prof$Profundidad_cat)
moda_prof <- names(tabla_freq_prof)[which.max(tabla_freq_prof)]
tabla_indicadores_prof <- data.frame(
Indicador = c("Tamaño muestral (n)", "Moda"),
Resultado = c(sum(tabla_freq_prof), moda_prof)
)
tabla_indicadores_prof %>%
gt() %>%
tab_header(
title = md("**Tabla N°1**"),
subtitle = md("Indicadores Estadísticos de la Profundidad de Recolección")
)| Tabla N°1 | |
| Indicadores Estadísticos de la Profundidad de Recolección | |
| Indicador | Resultado |
|---|---|
| Tamaño muestral (n) | 26971 |
| Moda | Poco profundo |