Reading layer `Departamento' from data source
`C:\Users\LENOVO\Downloads\Servicio-609\Departamentos_Junio_2024_shp\Departamentos_Junio_2024_shp\Departamento.shp'
using driver `ESRI Shapefile'
Simple feature collection with 33 features and 6 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 4047822 ymin: 1090467 xmax: 5684465 ymax: 3053707
Projected CRS: MAGNA-SIRGAS 2018 / Origen-Nacional
package 'RColorBrewer' successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\LENOVO\AppData\Local\Temp\RtmpicX4Il\downloaded_packages
library(ggplot2)
ggplot(conteo_de_sismos_Mayor_5, aes(x = reorder(DEPARTAMENTO, -n), y = n, fill = -n)) + geom_bar(stat = “identity”) + geom_text(aes(label = n), vjust = 0.5, color = “olivedrab”, size = 4) + coord_flip() + labs( x = “Departamento”, y = “Número de Sismos”, title = “Número de Sismos por Departamento Magnitud Ml Mayor a 5” ) + theme_light() + theme( panel.background = element_rect(fill = “grey”), # Cambia el color del fondo del área del gráfico plot.background = element_rect(fill = “white”) # Cambia el color del fondo del gráfico completo )
package 'plotly' successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\LENOVO\AppData\Local\Temp\RtmpicX4Il\downloaded_packages
package 'shiny' successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\LENOVO\AppData\Local\Temp\RtmpicX4Il\downloaded_packages
Reading layer `Departamento' from data source
`C:\Users\LENOVO\Downloads\Servicio-609\Departamentos_Junio_2024_shp\Departamentos_Junio_2024_shp\Departamento.shp'
using driver `ESRI Shapefile'
Simple feature collection with 33 features and 6 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 4047822 ymin: 1090467 xmax: 5684465 ymax: 3053707
Projected CRS: MAGNA-SIRGAS 2018 / Origen-Nacional
---
title: "Sismicidad en Colombia 2014-2024"
author: "Andrea Pablos"
output:
flexdashboard::flex_dashboard:
orientation: columns
social: menu
source_code: embed
---
```{r setup, include=FALSE}
library(highcharter)
library(dplyr)
library(viridisLite)
library(forecast)
library(treemap)
library(arules)
library(flexdashboard)
library(readxl)
library(tidyverse)
library(ggplot2)
Sismos <- read_xlsx("C:\\Users\\LENOVO\\Downloads\\Catalogo_Sismico_2014-2018_SGC (1) (version 1).xlsx")
thm <-
hc_theme(
colors = c("#1a6ecc", "#434348", "#90ed7d"),
chart = list(
backgroundColor = "transparent",
style = list(fontFamily = "Source Sans Pro")
),
xAxis = list(
gridLineWidth = 1
)
)
```
Column {.tabset data-width=400}
-----------------------------------------------------------------------
### MAPA DE SISMOS 2014-2024
```{r, }
set.seed(4)
nprods <- 10
library(readxl)
Sismos <- read_xlsx("C:\\Users\\LENOVO\\Downloads\\Catalogo_Sismico_2014-2018_SGC (1) (version 1).xlsx")
# Asegúrate de que los paquetes necesarios estén cargados
library(dplyr)
library(tidyr)
# Filtrar magnitudes de sismos Ml y realizar modificaciones
Magnitud_Ml_de_Sismos <- Sismos %>%
drop_na(`MAGNITUD Ml`) %>% # Elimina las filas con NA en la columna MAGNITUD Ml
filter(!DEPARTAMENTO %in% c("Ecuador", "Ecuador Border Region", "Venezuela", "Esmeraldas", "Carchi")) %>% # Filtrar departamentos específicos
mutate(
HORA_UTC = sub("1899-12-31 ", "", HORA_UTC), # Reemplazar parte de la cadena en HORA_UTC
FECHA = sub(" 00:00:00.00", "", FECHA) # Reemplazar parte de la cadena en FECHA
)
# Establecer un espejo CRAN
options(repos = c(CRAN = "https://cloud.r-project.org/"))
# Convertir el data frame a un objeto sf
library(sf)
mapa_base <- st_read("C:\\Users\\LENOVO\\Downloads\\Servicio-609\\Departamentos_Junio_2024_shp\\Departamentos_Junio_2024_shp\\Departamento.shp")
sismos_sf <- Magnitud_Ml_de_Sismos %>%
st_as_sf(coords = c("LONGITUD (grados)", "LATITUD (grados)"), crs = 4326) # Usar el CRS WGS 84
# Crear el mapa con ggplot2
install.packages(c("ggplot2", "sf", "RColorBrewer"))
library(RColorBrewer) # Para paletas de colores
library(ggplot2)
ggplot() +
geom_sf(data = mapa_base, fill = "lightgrey", color = "white") + # Añadir el mapa base
geom_sf(data = sismos_sf, aes(size = `PROFUNDIDAD (Km)`, color = `MAGNITUD Ml`), alpha = 0.7) + # Añadir los sismos
scale_size(range = c(1, 2.5), name = "Profundidad (Km)") + # Ajustar el rango de tamaños de los puntos
scale_color_gradientn(colors = brewer.pal(9, "YlOrRd"), name = "Magnitud Ml") + # Ajustar el rango de colores
labs(title = "Mapa de Sismos",
subtitle = "Distribución, Magnitud y Profunidad de los Sismos en Colombia 2014-2024",
x = "Longitud",
y = "Latitud") +
theme_minimal() # Usar un tema limpio para el mapa
```
### PROFUNDIDADES DE SISMOS
```{r, }
set.seed(4)
nprods <- 10
library(ggplot2)
library(dplyr)
library(RColorBrewer)
# Filtrar profundidades por valores negativos por errores de velocidades
library(sf)
sismos_sf <- Magnitud_Ml_de_Sismos %>%
st_as_sf(coords = c("LONGITUD (grados)", "LATITUD (grados)"), crs = 4326) # Usar el CRS WGS 84
Sismos_filtrados_Profundidad <- sismos_sf%>%
filter(`PROFUNDIDAD (Km)` >= 0)
#funcion para calculo de moda
mode_function <- function(x) {
uniq_x <- unique(x)
uniq_x[which.max(tabulate(match(x, uniq_x)))]
}
# Profundiddes de sismos por departamento
Distribucion_Profundidades_sismos <- Sismos_filtrados_Profundidad %>%
group_by(DEPARTAMENTO) %>% # Agrupar por departamento
summarise(
Moda = mode_function(`PROFUNDIDAD (Km)`), # Calcular la moda
Min_Profundidad = min(`PROFUNDIDAD (Km)`, na.rm = TRUE), # Calcular el valor mínimo
Max_Profundidad = max(`PROFUNDIDAD (Km)`, na.rm = TRUE), # Calcular el valor máximo
Numero_de_Sismos = n() # Contar el número de sismos por departamento
)
#Grafica de profundidades maximas Vs Numero de sismos
ggplot(Distribucion_Profundidades_sismos, aes(x = reorder(DEPARTAMENTO, Max_Profundidad))) +
geom_bar(aes(y = Max_Profundidad, fill = Max_Profundidad), stat = "identity", alpha = 0.6) +
geom_line(aes(y = Numero_de_Sismos * max(Distribucion_Profundidades_sismos$Max_Profundidad) / max(Distribucion_Profundidades_sismos$Numero_de_Sismos), group = 1),
color = "red", size = 0.5) +
geom_point(aes(y = Numero_de_Sismos * max(Distribucion_Profundidades_sismos$Max_Profundidad) / max(Distribucion_Profundidades_sismos$Numero_de_Sismos)),
color = "red", size = 1) +
geom_text(aes(
label = Numero_de_Sismos,
y = Numero_de_Sismos * max(Distribucion_Profundidades_sismos$Max_Profundidad) / max(Distribucion_Profundidades_sismos$Numero_de_Sismos) + 0.5),
color = "black", size = 3) +
coord_flip() +
scale_y_continuous(sec.axis = sec_axis(~ . * max(Distribucion_Profundidades_sismos$Numero_de_Sismos) / max(Distribucion_Profundidades_sismos$Max_Profundidad), name = "Número de Sismos")) +
labs(
x = "Departamento",
y = "Profundidad Máxima",
title = "Profundidad Máxima y
Número de Sismos por
Departamento"
) +
theme_light() +
theme(
panel.background = element_rect(fill = "grey"),
plot.background = element_rect(fill = "white"),
axis.text.y = element_text(size = 8)
)
# Crear la gráfica de barras para la moda de profundidad Vs Departamento
ggplot(Distribucion_Profundidades_sismos, aes(x = DEPARTAMENTO, y = Moda)) +
geom_bar(stat = "identity", fill = "steelblue") +
theme_minimal() +
coord_flip()+
labs(
title = "Moda de la Profundidad
de Sismos por Departamento",
x = "Departamento",
y = "Moda de Profundidad (Km)"
) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
theme_light() +
theme(
panel.background = element_rect(fill = "grey"),
plot.background = element_rect(fill = "white"),
axis.text.y = element_text(size = 8)
)
```
### PROFUNDIDAD DE LOS SISMOS Vs MAGNITUD
```{r, }
set.seed(4)
nprods <- 10
# Profundidad Vs Magnitid de Sismos
ggplot(Sismos_filtrados_Profundidad, aes(x = `MAGNITUD Ml`, y = `PROFUNDIDAD (Km)`)) +
geom_point(color = "steelblue", alpha = 0.7) + # Añade puntos con color y transparencia
theme_minimal() + # Usa un tema limpio y minimalista
labs(
title = "Profundidad Vs Magnitud de Sismos",
x = "Magnitud de Sismos",
y = "Profundidad (Km)"
)+
xlim(2.5, 7) + # Ajusta los límites del eje x
ylim(0, 270) # Ajusta los límites del eje y
```
### MAPA DE SISMOS MAYORES A 5
```{r, }
set.seed(4)
nprods <- 10
# Filtrar Magnitudes mayores a 5
Sismos_filtrados_Magnitud_Mayor_5 <- sismos_sf%>%
filter(`MAGNITUD Ml` >= 5)
Sismos_filtrados_Magnitud_Mayor_5_Sf <- Sismos_filtrados_Magnitud_Mayor_5 %>%
st_as_sf(coords = c("LONGITUD (grados)", "LATITUD (grados)"), crs = 4326) # Usar el CRS WGS 84
# Crear el mapa con ggplot2
install.packages(c("ggplot2", "sf", "RColorBrewer"))
library(RColorBrewer) # Para paletas de colores
library(ggplot2)
Mapa_Sismos_Mayor_5=ggplot() +
geom_sf(data = mapa_base, fill = "lightgrey", color = "white") + # Añadir el mapa base
geom_sf(data = Sismos_filtrados_Magnitud_Mayor_5_Sf, aes(size = `PROFUNDIDAD (Km)`, color = `MAGNITUD Ml`), alpha = 0.7) + # Añadir los sismos
scale_size(range = c(0.5, 2), name = "Profundidad (Km)") + # Ajustar el rango de tamaños de los puntos
scale_color_gradientn(colors = brewer.pal(9, "YlOrRd"), name = "Magnitud Ml") + # Ajustar el rango de colores
labs(title = "Mapa de Sismos de Magnitud Ml mayor a
5 en Colombia 2014-2024",
subtitle = "DistribucióN Sismos",
x = "Longitud",
y = "Latitud") +
theme_minimal() # Usar un tema limpio para el mapa
Mapa_Sismos_Mayor_5
```
library(ggplot2)
ggplot(conteo_de_sismos_Mayor_5, aes(x = reorder(DEPARTAMENTO, -n), y = n, fill = -n)) +
geom_bar(stat = "identity") +
geom_text(aes(label = n), vjust = 0.5, color = "olivedrab", size = 4) +
coord_flip() +
labs(
x = "Departamento",
y = "Número de Sismos",
title = "Número de Sismos por Departamento
Magnitud Ml Mayor a 5"
) +
theme_light() +
theme(
panel.background = element_rect(fill = "grey"), # Cambia el color del fondo del área del gráfico
plot.background = element_rect(fill = "white") # Cambia el color del fondo del gráfico completo
)
Column {.tabset data-width=400}
-----------------------------------------------------------------------
### NUMERO DE SISMOS POR DEPARTAMENTO
```{r, }
Sismos <- read_xlsx("C:\\Users\\LENOVO\\Downloads\\Catalogo_Sismico_2014-2018_SGC (1) (version 1).xlsx")
conteo_de_sismos = Sismos %>%
drop_na(DEPARTAMENTO) %>% # Elimina las filas con NA en la columna DEPARTAMENTO
filter(!DEPARTAMENTO %in% c("Ecuador", "Ecuador Border Region", "Venezuela", "Esmeraldas", "Carchi")) %>% # Filtra los departamentos que no sean los excluidos
count(DEPARTAMENTO) %>% # Cuenta el número de sismos por departamento
arrange(desc(n)) # Ordena en orden descendente por el conteo
ggplot(conteo_de_sismos, aes(x = reorder(DEPARTAMENTO, -n), y = n, fill = -n)) +
geom_bar(stat = "identity") +
geom_text(aes(label = n), vjust = 0.5, color = "olivedrab", size = 2) +
coord_flip() +
labs(
x = "Departamento",
y = "Número de Sismos",
title = "Número de Sismos
por Departamento"
) +
theme_light() +
theme(
panel.background = element_rect(fill = "grey"), # Cambia el color del fondo del área del gráfico
plot.background = element_rect(fill = "white") # Cambia el color del fondo del gráfico completo
)
```
### COMPORTAMIENTO DE MAGNITUDES
```{r, }
#Histograma de frecuenca
ggplot(Magnitud_Ml_de_Sismos, aes(x = `MAGNITUD Ml`)) +
geom_histogram(binwidth = 0.1, fill = "steelblue", color = "black") +
theme_minimal() +
labs(
title = "Histograma de Frecuencia de Sismos",
x = "Magnitud de Sismos",
y = "Frecuencia"
) +
xlim(2, 7) + # Ajusta los límites del eje x
ylim(0, 3000) # Ajusta los límites del eje y
library(dplyr)
#Estadistica descriptiva por Departamento para la Magnitud Ml
Distribucion_Magnitudes_Ml= Magnitud_Ml_de_Sismos %>%
group_by(DEPARTAMENTO) %>% # Agrupar por departamento
summarise(
Media = mean(`MAGNITUD Ml`, na.rm = TRUE),
Mediana = median(`MAGNITUD Ml`, na.rm = TRUE),
Desviacion_Estandar = sd(`MAGNITUD Ml`, na.rm = TRUE))
#funcion para cálculo de moda
mode_function <- function(x) {
uniq_x <- unique(x)
uniq_x[which.max(tabulate(match(x, uniq_x)))]
}
Distribucion_Magnitudes_Ml_por_Departamento <- Magnitud_Ml_de_Sismos%>%
group_by(DEPARTAMENTO) %>% # Agrupar por departamento
summarise(
Moda = mode_function(`MAGNITUD Ml`), # Calcular la moda
Min_Magnitud = min(`MAGNITUD Ml`, na.rm = TRUE), # Calcular el valor mínimo
Max_Magnitud = max(`MAGNITUD Ml`, na.rm = TRUE), # Calcular el valor máximo
Numero_de_Sismos = n() # Contar el número de sismos por departamento
)
#graficar la moda Vs Departamento
ggplot(Distribucion_Magnitudes_Ml_por_Departamento, aes(x = DEPARTAMENTO, y = Moda, fill = DEPARTAMENTO)) +
geom_bar(stat = "identity") +
theme_minimal() +
coord_flip()+
labs(
title = "Moda de Valor de Magnitud
Ml de Sismos por Departamento",
x = "Departamento",
y = "Moda de Magnitud Ml"
) +
theme(
axis.text.x = element_text(angle = 0, hjust = 1),
legend.position = "none"
)
```
### MAGNITUD MAXIMA Y SISMOS POR DEPARTAMENTO
```{r, }
set.seed(4)
nprods <- 10
#Graficar Magnitud Maxima y numero de sismos Vs Departamento
library(ggplot2)
library(dplyr)
ggplot(Distribucion_Magnitudes_Ml_por_Departamento, aes(x = reorder(DEPARTAMENTO, Max_Magnitud))) +
geom_bar(aes(y = Max_Magnitud, fill = Max_Magnitud), stat = "identity", alpha = 0.6) +
geom_line(aes(y = Numero_de_Sismos * max(Distribucion_Magnitudes_Ml_por_Departamento$Max_Magnitud) / max(Distribucion_Magnitudes_Ml_por_Departamento$Numero_de_Sismos), group = 1),
color = "red", size = 0.5) +
geom_point(aes(y = Numero_de_Sismos * max(Distribucion_Magnitudes_Ml_por_Departamento$Max_Magnitud) / max(Distribucion_Magnitudes_Ml_por_Departamento$Numero_de_Sismos)),
color = "red", size = 1) +
geom_text(aes(
label = Numero_de_Sismos,
y = Numero_de_Sismos * max(Distribucion_Magnitudes_Ml_por_Departamento$Max_Magnitud) / max(Distribucion_Magnitudes_Ml_por_Departamento$Numero_de_Sismos) + 0.5),
color = "black", size = 3) +
coord_flip() +
scale_y_continuous(sec.axis = sec_axis(~ . * max(Distribucion_Magnitudes_Ml_por_Departamento$Numero_de_Sismos) / max(Distribucion_Magnitudes_Ml_por_Departamento$Max_Magnitud), name = "# Total de Sismos")) +
labs(
x = "Departamento",
y = "Magnitud Ml Máxima",
title = "Magnitud Máxima y
Número de Sismos
por Departamento"
) +
theme_light() +
theme(
panel.background = element_rect(fill = "grey"),
plot.background = element_rect(fill = "white"),
axis.text.y = element_text(size = 7.5)
)
```
### MAPAS DE SISMICIDAD POR AÑO
```{r fig.height=12, fig.width=15}
set.seed(4)
nprods <- 10
# Cargar librerías
library(sf)
library(lubridate)
library(ggplot2)
install.packages("plotly")
library(plotly)
library(RColorBrewer)
install.packages("shiny")
library(shiny)
mapa_base <- st_read("C:\\Users\\LENOVO\\Downloads\\Servicio-609\\Departamentos_Junio_2024_shp\\Departamentos_Junio_2024_shp\\Departamento.shp")
sismos_sf <- Magnitud_Ml_de_Sismos %>%
st_as_sf(coords = c("LONGITUD (grados)", "LATITUD (grados)"), crs = 4326) # Usar el CRS WGS 84
# Convertir la columna FECHA a formato Date si no lo está ya
sismos_sf$FECHA <- as.Date(sismos_sf$FECHA)
# Extraer solo el año y guardarlo en una nueva columna AÑO
sismos_sf$AÑO <- year(sismos_sf$FECHA)
# Crear el mapa de calor por años
heatmap <- ggplot() +
geom_sf(data = mapa_base, fill = "lightgrey", color = "white") + # Añadir el mapa base
geom_sf(data = sismos_sf, aes(size = `PROFUNDIDAD (Km)`, color = `MAGNITUD Ml`), alpha = 0.7) + # Añadir los sismos
scale_size(range = c(0.5, 2), name = "Profundidad (Km)") + # Ajustar el rango de tamaños de los puntos
scale_color_gradientn(colors = brewer.pal(9, "YlOrRd"), name = "Magnitud Ml") + # Ajustar el rango de colores
facet_wrap(~ AÑO, ncol = 4) + # Crear una faceta por año
labs(title = "Mapa de Calor de Sismos por Año",
subtitle = "Distribución, Magnitud y Profundidad
de los Sismos por Año",
x = "Longitud",
y = "Latitud") +
theme_minimal() + # Usar un tema limpio para el mapa
theme(legend.position = "bottom") # Ajustar la posición de la leyenda
# Mostrar el mapa de calor
print(heatmap)
```