# 2. Construir la Tabla de Frecuencias (ordenada de mayor a menor frecuencia)
tdf_magtype <- datos_magtype %>%
count(tipo_mag, name = "ni") %>%
arrange(desc(ni)) %>%
mutate(
hi = ni / sum(ni),
hi_txt = sprintf("%.4f", hi)
)
# 3. Añadir Fila de Totales
total_n_mt <- sum(tdf_magtype$ni)
tdf_magtype_final <- tdf_magtype %>%
select(Clase = tipo_mag, ni, hi = hi_txt) %>%
add_row(
Clase = "Total",
ni = total_n_mt,
hi = "1.0000"
)
# 4. Formato Visual Académico (Estilo APA)
tdf_magtype_final %>%
gt() %>%
cols_label(
Clase = html("Tipo de magnitud<br>(magType)"),
ni = html("Frecuencia<br>absoluta<br>n<sub>i</sub> (FA)"),
hi = html("Frecuencia<br>relativa<br>h<sub>i</sub> (FR)")
) %>%
tab_header(
title = md("**Tabla N° 1**"),
subtitle = "Tipo de magnitud de los terremotos ocurridos a nivel global"
) %>%
tab_source_note(
source_note = "Elaborado por: Grupo 3 - Geología."
) %>%
cols_align(
align = "center",
columns = everything()
) %>%
tab_options(
table.font.names = "Times New Roman",
table.border.top.color = "transparent",
column_labels.border.top.color = "black",
column_labels.border.top.width = px(2),
column_labels.border.bottom.color = "black",
column_labels.border.bottom.width = px(2),
table_body.hlines.color = "transparent",
table_body.border.bottom.color = "black",
table_body.border.bottom.width = px(2)
)| Tabla N° 1 | ||
| Tipo de magnitud de los terremotos ocurridos a nivel global | ||
| Tipo de magnitud (magType) |
Frecuencia absoluta ni (FA) |
Frecuencia relativa hi (FR) |
|---|---|---|
| mww | 551 | 0.4846 |
| ml | 351 | 0.3087 |
| mb | 124 | 0.1091 |
| mwr | 53 | 0.0466 |
| mw | 36 | 0.0317 |
| mb_lg | 16 | 0.0141 |
| Mi | 2 | 0.0018 |
| Ml | 2 | 0.0018 |
| mwb | 2 | 0.0018 |
| Total | 1137 | 1.0000 |
| Elaborado por: Grupo 3 - Geología. | ||
# --- GRÁFICA LOCAL ni ---
par(mar = c(5, 5, 7, 2))
ni_mt <- tdf_magtype$ni
etiquetas_mt <- tdf_magtype$tipo_mag
max_ni_mt <- max(ni_mt)
barplot(ni_mt,
names.arg = etiquetas_mt,
col = "#FF0000",
border = "black",
space = 0.25, # Barras separadas (variable cualitativa)
las = 1,
cex.names = 0.85,
ylim = c(0, max_ni_mt * 1.15),
yaxt = "n",
main = "",
xlab = "Tipo de magnitud (magType)",
ylab = "Frecuencia absoluta ni")
mtext("Gráfica N° 1. Frecuencia absoluta del tipo de magnitud de terremotos\na nivel global (local)",
side = 3, line = 2.5, cex = 0.9, font = 2)
ticks_y_ni <- round(seq(0, max_ni_mt, length.out = 5), 0)
axis(side = 2, at = ticks_y_ni, labels = ticks_y_ni, las = 1)A partir del análisis estadístico descriptivo de la variable
cualitativa nominal Tipo de magnitud
(magtype) en una muestra total de 1,137 eventos
sísmicos registrados a nivel mundial, se concluye que: