library(readxl)
library(dplyr)
##
## Attaching package: '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)
# =========================
# 1️⃣ Cargar base de datos
# =========================
datos_nuevoartes <- read_excel("datos_nuevoartes.xlsx")
# ====================================================
# ====== TABLA DE FRECUENCIAS: LONGITUDE ==============
# ====================================================
longitude <- datos_nuevoartes$longitude
longitude <- longitude[!is.na(longitude)]
n_long <- length(longitude)
k_long <- floor(1 + 3.3 * log10(n_long))
min_long <- min(longitude)
max_long <- max(longitude)
R_long <- max_long - min_long
A_long <- R_long / k_long
Li_long <- round(seq(min_long, max_long - A_long, by = A_long), 6)
Ls_long <- round(seq(min_long + A_long, max_long, by = A_long), 6)
MC_long <- round((Li_long + Ls_long) / 2, 2)
ni_long <- numeric(length(Li_long))
for (i in 1:length(Li_long)) {
ni_long[i] <- sum(longitude >= Li_long[i] & longitude < Ls_long[i])
}
ni_long[length(ni_long)] <- sum(longitude >= Li_long[length(Li_long)] & longitude <= max_long)
hi_long <- round((ni_long / sum(ni_long)) * 100, 5)
Ni_asc_long <- cumsum(ni_long)
Ni_dsc_long <- rev(cumsum(rev(ni_long)))
Hi_asc_long <- round(cumsum(hi_long), 2)
Hi_dsc_long <- round(rev(cumsum(rev(hi_long))), 2)
TDF_longitude <- data.frame(
Li = Li_long,
Ls = Ls_long,
MC = MC_long,
ni = ni_long,
hi = hi_long,
Ni_asc = Ni_asc_long,
Ni_dsc = Ni_dsc_long,
Hi_asc = Hi_asc_long,
Hi_dsc = Hi_dsc_long
)
# Fila TOTAL
TDF_longitude <- rbind(
TDF_longitude,
data.frame(
Li = "TOTAL",
Ls = "",
MC = "",
ni = sum(ni_long),
hi = 100,
Ni_asc = "",
Ni_dsc = "",
Hi_asc = "",
Hi_dsc = ""
)
)
tabla_longitude <- TDF_longitude %>%
gt() %>%
fmt_number(columns = MC, decimals = 2) %>%
tab_header(
title = md("**Tabla N° 1**"),
subtitle = md("**Tabla de distribución de frecuencias simples y acumuladas de Longitude**")
) %>%
tab_source_note(
source_note = md("Autor: Alessandro")
) %>%
tab_style(
style = cell_text(weight = "bold"),
locations = cells_body(rows = Li == "TOTAL")
)
tabla_longitude
| Tabla N° 1 |
| Tabla de distribución de frecuencias simples y acumuladas de Longitude |
| Li |
Ls |
MC |
ni |
hi |
Ni_asc |
Ni_dsc |
Hi_asc |
Hi_dsc |
| -179.980766 |
-154.268471 |
-167.12 |
79 |
0.71603 |
79 |
11033 |
0.72 |
100 |
| -154.268471 |
-128.556176 |
-141.41 |
45 |
0.40787 |
124 |
10954 |
1.12 |
99.28 |
| -128.556176 |
-102.843881 |
-115.7 |
2803 |
25.40560 |
2927 |
10909 |
26.53 |
98.88 |
| -102.843881 |
-77.131586 |
-89.99 |
1239 |
11.22995 |
4166 |
8106 |
37.76 |
73.47 |
| -77.131586 |
-51.419291 |
-64.28 |
573 |
5.19351 |
4739 |
6867 |
42.95 |
62.24 |
| -51.419291 |
-25.706996 |
-38.56 |
215 |
1.94870 |
4954 |
6294 |
44.9 |
57.05 |
| -25.706996 |
0.005299 |
-12.85 |
317 |
2.87320 |
5271 |
6079 |
47.77 |
55.1 |
| 0.005299 |
25.717594 |
12.86 |
300 |
2.71912 |
5571 |
5762 |
50.49 |
52.23 |
| 25.717594 |
51.429889 |
38.57 |
306 |
2.77350 |
5877 |
5462 |
53.27 |
49.51 |
| 51.429889 |
77.142184 |
64.29 |
838 |
7.59540 |
6715 |
5156 |
60.86 |
46.73 |
| 77.142184 |
102.854479 |
90 |
2104 |
19.07006 |
8819 |
4318 |
79.93 |
39.14 |
| 102.854479 |
128.566774 |
115.71 |
1760 |
15.95214 |
10579 |
2214 |
95.89 |
20.07 |
| 128.566774 |
154.279069 |
141.42 |
251 |
2.27499 |
10830 |
454 |
98.16 |
4.11 |
| 154.279069 |
179.991364 |
167.14 |
203 |
1.83993 |
11033 |
203 |
100 |
1.84 |
| TOTAL |
|
|
11033 |
100.00000 |
|
|
|
|
| Autor: Alessandro |
# =============================
# HISTOGRAMAS – LONGITUDE
# =============================
# HISTOGRAMA LOCAL ni
hist(
longitude,
main = "Gráfica Nº 1: Frecuencia de Longitude (Local)",
ylab = "Cantidad",
xlab = "Longitude (°)",
col = "grey"
)

# HISTOGRAMA GLOBAL ni
hist(
longitude,
main = "Gráfica Nº 2: Frecuencia de Longitude (Global)",
ylab = "Cantidad",
xlab = "Longitude (°)",
col = "grey",
ylim = c(0, length(longitude))
)

# HISTOGRAMA LOCAL hi
barplot(
TDF_longitude$hi[TDF_longitude$Li != "TOTAL"],
space = 0,
main = "Gráfica Nº 3: Porcentaje de Longitude (Local)",
ylab = "Porcentaje (%)",
xlab = "Marca de Clase (°)",
col = "grey",
names.arg = TDF_longitude$MC[TDF_longitude$Li != "TOTAL"]
)

# HISTOGRAMA GLOBAL hi
barplot(
TDF_longitude$hi[TDF_longitude$Li != "TOTAL"],
space = 0,
main = "Gráfica Nº 4: Porcentaje de Longitude (Global)",
ylab = "Porcentaje (%)",
xlab = "Marca de Clase (°)",
col = "grey",
names.arg = TDF_longitude$MC[TDF_longitude$Li != "TOTAL"],
ylim = c(0, 100)
)

# ====================================================
# ====== TABLA DE FRECUENCIAS: LATITUDE ===============
# ====================================================
latitude <- datos_nuevoartes$latitude
latitude <- latitude[!is.na(latitude)]
n_lat <- length(latitude)
k_lat <- floor(1 + 3.3 * log10(n_lat))
min_lat <- min(latitude)
max_lat <- max(latitude)
R_lat <- max_lat - min_lat
A_lat <- R_lat / k_lat
Li_lat <- round(seq(min_lat, max_lat - A_lat, by = A_lat), 6)
Ls_lat <- round(seq(min_lat + A_lat, max_lat, by = A_lat), 6)
MC_lat <- round((Li_lat + Ls_lat) / 2, 2)
ni_lat <- numeric(length(Li_lat))
for (i in 1:length(Li_lat)) {
ni_lat[i] <- sum(latitude >= Li_lat[i] & latitude < Ls_lat[i])
}
ni_lat[length(ni_lat)] <- sum(latitude >= Li_lat[length(Li_lat)] & latitude <= max_lat)
hi_lat <- round((ni_lat / sum(ni_lat)) * 100, 5)
Ni_asc_lat <- cumsum(ni_lat)
Ni_dsc_lat <- rev(cumsum(rev(ni_lat)))
Hi_asc_lat <- round(cumsum(hi_lat), 2)
Hi_dsc_lat <- round(rev(cumsum(rev(hi_lat))), 2)
TDF_latitude <- data.frame(
Li = Li_lat,
Ls = Ls_lat,
MC = MC_lat,
ni = ni_lat,
hi = hi_lat,
Ni_asc = Ni_asc_lat,
Ni_dsc = Ni_dsc_lat,
Hi_asc = Hi_asc_lat,
Hi_dsc = Hi_dsc_lat
)
# Fila TOTAL
TDF_latitude <- rbind(
TDF_latitude,
data.frame(
Li = "TOTAL",
Ls = "",
MC = "",
ni = sum(ni_lat),
hi = 100,
Ni_asc = "",
Ni_dsc = "",
Hi_asc = "",
Hi_dsc = ""
)
)
tabla_latitude <- TDF_latitude %>%
gt() %>%
fmt_number(columns = MC, decimals = 2) %>%
tab_header(
title = md("**Tabla N° 2**"),
subtitle = md("**Tabla de distribución de frecuencias simples y acumuladas de Latitude**")
) %>%
tab_source_note(
source_note = md("Autor: Alessandro")
) %>%
tab_style(
style = cell_text(weight = "bold"),
locations = cells_body(rows = Li == "TOTAL")
)
tabla_latitude
| Tabla N° 2 |
| Tabla de distribución de frecuencias simples y acumuladas de Latitude |
| Li |
Ls |
MC |
ni |
hi |
Ni_asc |
Ni_dsc |
Hi_asc |
Hi_dsc |
| -46.7748 |
-38.246064 |
-42.51 |
130 |
1.17828 |
130 |
11033 |
1.18 |
100 |
| -38.246064 |
-29.717329 |
-33.98 |
123 |
1.11484 |
253 |
10903 |
2.29 |
98.82 |
| -29.717329 |
-21.188593 |
-25.45 |
236 |
2.13904 |
489 |
10780 |
4.43 |
97.71 |
| -21.188593 |
-12.659857 |
-16.92 |
143 |
1.29611 |
632 |
10544 |
5.73 |
95.57 |
| -12.659857 |
-4.131121 |
-8.4 |
365 |
3.30826 |
997 |
10401 |
9.04 |
94.27 |
| -4.131121 |
4.397614 |
0.13 |
432 |
3.91553 |
1429 |
10036 |
12.95 |
90.96 |
| 4.397614 |
12.92635 |
8.66 |
1212 |
10.98523 |
2641 |
9604 |
23.94 |
87.05 |
| 12.92635 |
21.455086 |
17.19 |
1042 |
9.44439 |
3683 |
8392 |
33.38 |
76.06 |
| 21.455086 |
29.983821 |
25.72 |
1723 |
15.61679 |
5406 |
7350 |
49 |
66.62 |
| 29.983821 |
38.512557 |
34.25 |
2136 |
19.36010 |
7542 |
5627 |
68.36 |
51 |
| 38.512557 |
47.041293 |
42.78 |
2463 |
22.32394 |
10005 |
3491 |
90.68 |
31.64 |
| 47.041293 |
55.570029 |
51.31 |
893 |
8.09390 |
10898 |
1028 |
98.78 |
9.32 |
| 55.570029 |
64.098764 |
59.83 |
129 |
1.16922 |
11027 |
135 |
99.95 |
1.22 |
| 64.098764 |
72.6275 |
68.36 |
6 |
0.05438 |
11033 |
6 |
100 |
0.05 |
| TOTAL |
|
|
11033 |
100.00000 |
|
|
|
|
| Autor: Alessandro |
# =============================
# HISTOGRAMAS – LATITUDE
# =============================
# HISTOGRAMA LOCAL ni
hist(
latitude,
main = "Gráfica Nº 5: Frecuencia de Latitude (Local)",
ylab = "Cantidad",
xlab = "Latitude (°)",
col = "grey"
)

# HISTOGRAMA GLOBAL ni
hist(
latitude,
main = "Gráfica Nº 6: Frecuencia de Latitude (Global)",
ylab = "Cantidad",
xlab = "Latitude (°)",
col = "grey",
ylim = c(0, length(latitude))
)

# HISTOGRAMA LOCAL hi
barplot(
TDF_latitude$hi[TDF_latitude$Li != "TOTAL"],
space = 0,
main = "Gráfica Nº 7: Porcentaje de Latitude (Local)",
ylab = "Porcentaje (%)",
xlab = "Marca de Clase (°)",
col = "grey",
names.arg = TDF_latitude$MC[TDF_latitude$Li != "TOTAL"]
)

# HISTOGRAMA GLOBAL hi
barplot(
TDF_latitude$hi[TDF_latitude$Li != "TOTAL"],
space = 0,
main = "Gráfica Nº 8: Porcentaje de Latitude (Global)",
ylab = "Porcentaje (%)",
xlab = "Marca de Clase (°)",
col = "grey",
names.arg = TDF_latitude$MC[TDF_latitude$Li != "TOTAL"],
ylim = c(0, 100)
)
