The dataset I’ll use in the Final Project is called “Earthquake Events Worldwide 2023”. The data collection involves web scraping on the Euro-Mediterranean Seismological Centre. Currently, the dataset has 53,539 observations (earthquakes). It contains 7 columns, which are Date and Time, Latitude, Longitude, Depth (in KM - earthquake’s focus below the Earth’s surface, measured in kilometers), magnitude (representing the energy released. It goes from -1, which are so small that they are expressed in negative numbers, to 10, which are the strongest ones), lands (type of land or region affected by the earthquake) and country. The author uses “selenium automation in the EMSC website”, which ensures the extraction of up-to-date and accurate data. With the data provided, I will try to analyze trends, patterns and distributions of earthquakes around the globe. Magnitude and depth are quantitative variables. Land and country are categorical. Latitude and longitude are considered continuous numerical data. I chose this topic because I’ve always been interested in natural phenomena and this dataset contains information that allows me to dig into this topic. Also, it helps me understand better the world zones and the likelihood that earthquakes may occur. Throughout this project, I will try to answer few questions, such as at what frequency does each magnitude occur? What are the countries that have the highest incidence of earthquakes? Where did the earthquakes occur in the year 2023? Are there specific areas on the planet that had more than one earthquake in 2023? Ps: Since the dataset is updated daily, it’s important to mention that the last update I got was from 4 days ago (12-09-2023), and the dataset had 53539 observations then. Now, it will probably have a higher number.
Dataset source: Euro-Mediterranean Seismological Centre.
Dataset collection form: According to the EMSC website, “EMSC operates a system for rapid collection, determination, and dissemination of earthquake parameters using seismic data contributed by seismological institutes around the world together with crowdsourced data from earthquake eyewitnesses.”
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(leaflet)
library(plotly)
##
## Attaching package: 'plotly'
##
## 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
library(viridis)
## Loading required package: viridisLite
setwd("/Users/andreassanches/Documents")
earthquakes_data <- read_csv("earthquake_data.csv")
## Rows: 53539 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): Date & Time, Lands, Country
## dbl (4): Latitude, Longitude, Depth, Magnitude
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
I removed the commas that some observations inside the “Lands” column had because they were incorrectly placed there. Also, I may explore this column further, and I don’t want these wrong commas to be shown in my output.
earthquakes_data <- earthquakes_data |>
mutate(Lands = str_replace_all(Lands, ",", ""))
# Visualization - Histogram of Earthquake Magnitudes
ggplot(earthquakes_data, aes(x = Magnitude, fill = ..count..)) +
geom_histogram(binwidth = 0.5, fill = "blue", color = "red", alpha = 0.7) + # Set fill color to "blue"
scale_fill_viridis(discrete = FALSE) +
theme_minimal() +
labs(title = "Distribution of Earthquake Magnitudes",
x = "Magnitude",
y = "Frequency",
caption = "Euro-Mediterranean Seismological Centre") +
theme(text = element_text(family = "Arial", color = "black"),
plot.title = element_text(hjust = 0.5),
axis.title = element_text(face = "bold"))
## Warning: The dot-dot notation (`..count..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(count)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
From this visualization, we can see that the “Distribution of Earthquake Magnitudes” looks like a normal distribution (bell-shaped), which has a center equal “3” and its magnitude goes from -0.7 to 7.7. We can also infer from the visualization that, fortunately, most of the earthquakes’ magnitude that have occurred so far in 2023 are between 1.8 and 3.9. That means that in addition to being “weak,” they also go mostly unnoticed.
The reason I’m doing this is for my last view. In it I intend to show where and what type of earthquake intensity occurred around the world.
quake_groups <- earthquakes_data |>
mutate(mag_group = ifelse(Magnitude%in% -1:2, "Low Magnitude",
ifelse(Magnitude%in% 2.1:4.0, "Medium Magnitude",
ifelse(Magnitude%in% 4.1:6.0, "High Magnitude", "Very High Magnitude"))))
strong_quakes <- earthquakes_data |>
filter(Magnitude >= 4.0)
I’m grouping the earthquakes by country and counting the number of earthquakes per country, following my requirements above. I’m selecting only the Top10.
top_countries <- strong_quakes |>
group_by(Country) |>
summarise(total_strong_quakes = n()) |>
arrange(desc(total_strong_quakes)) |>
slice_head(n = 10)
top_countries <- strong_quakes |>
group_by(Country) |>
summarise(total_strong_quakes = n(),
mean_depth = mean(Depth)) |>
filter(!Country %in% c("REGION", "ISLANDS", "RIDGE")) |>
arrange(desc(total_strong_quakes)) |>
slice_head(n = 10)
bar_chart_filtered <- ggplot(top_countries, aes(x = mean_depth, y = total_strong_quakes, fill = Country, text = paste("Total Strong Quakes: ", total_strong_quakes, "\nMean Depth: ", mean_depth))) +
geom_bar(stat = "identity") +
scale_fill_manual(values = c("#FF9999", "#66B2FF", "#99FF99", "grey", "#c2c2f0", "#ffb3e6", "black", "#ffb366", "#ff6666", "#c2f0f0")) +
labs(title = "Top 10 Countries With the Most Earthquakes of \nMedium Magnitude or Higher (>= 4.0)",
x = "Mean Depth",
y = "Number of Earthquakes", caption = "Euro-Mediterranean Seismological Centre") +
theme_minimal() +
theme(axis.text.x = element_text(angle = , hjust = 1))
interactive_plot_filtered <- ggplotly(bar_chart_filtered, tooltip = c("text"))
interactive_plot_filtered
Caption: Euro-Mediterranean Seismological Centre
Surprisingly, Mexico is the country with the highest number of earthquakes considered “medium magnitude” or stronger. Despite “SEA” is not a country, I left in the visualization to call the attention that at sea there is a great occurrence of strong earthquakes. “P.N.G” is also known as Papua New Guinea. I also excluded some “generic” terms that were in my visualization, such as “region”, “ridge” and “islands”, because they’re not countries. Besides being the country with most strong earthquakes, Mexico is the country with the smallest average depth of earthquakes, that is, earthquakes normally occur “close” to the earth’s surface.
I defined a color for each earthquake category
pal <- colorFactor(palette = c("blue", "red", "green", "yellow"),
levels = c("Low Magnitude", "Medium Magnitude", "High Magnitude", "Very High Magnitude"),
domain = quake_groups)
Below, we can see where the earthquakes occurred and their magnitude. It gives us a good idea of zones that have high incidence of earthquakes.
leaflet() |>
setView(lng = 0, lat = 20, zoom = 2) |>
addProviderTiles("Esri.WorldStreetMap") |>
addCircleMarkers(
data=quake_groups,
radius = 3, popup = ~paste("Magnitude: ", Magnitude, "<br>",
"Depth: ", Depth, " KM"),
fillColor = pal(quake_groups$mag_group),
fillOpacity = 5) |>
addLegend(
position = "bottomright",
colors = c("blue", "red", "green", "yellow"),
labels = c("Low Magnitude", "Medium Magnitude", "High Magnitude", "Very High Magnitude"),
opacity = 1
) |>
setView(lng = 0, lat = 20, zoom = 2)
## Assuming "Longitude" and "Latitude" are longitude and latitude, respectively
Caption: Euro-Mediterranean Seismological Centre
In this case, areas that have had more than one earthquake are highlighted with a pink circle. The circle is proportional to the number of earthquakes in that region, therefore, the larger the circle, the greater the recurrence.
# Group by location and calculate aggregated information
grouped_quakes <- earthquakes_data |>
group_by(Latitude, Longitude, Country) |>
summarise(
total_quakes = n(),
max_magnitude = max(Magnitude),
min_magnitude = min(Magnitude),
.groups = "drop" # Override grouping
)
# Create a color palette for circle colors
color_pal <- ifelse(grouped_quakes$total_quakes > 1, "pink", "black")
# Create a Leaflet map with circle markers
leaflet() |>
setView(lng = 0, lat = 20, zoom = 2) |>
addProviderTiles("Esri.WorldPhysical") |>
addCircleMarkers(
data = grouped_quakes,
radius = ~total_quakes,
fillColor = color_pal,
fillOpacity = 0.8,
color = "black",
stroke = TRUE,
weight = 1,
popup = ~paste(
"Country/Region: ", Country, "<br>",
"Total Quakes: ", total_quakes, "<br>",
"Max Magnitude: ", max_magnitude, "<br>",
"Min Magnitude: ", min_magnitude
)
) |>
addLegend(
position = "bottomright",
colors = c("black", "pink"),
labels = c("Single Earthquake", "Multiple Earthquakes"),
opacity = 1
)
## Assuming "Longitude" and "Latitude" are longitude and latitude, respectively
Caption: Euro-Mediterranean Seismological Centre
For those who don’t have a good sense of geography like me, I had to plot the maps so that you would have an idea of where earthquakes actually occur the most. It draws attention that in Russia for example, which is the largest country in the world, there is very little incidence of earthquakes, whereas in Japan and Indonesia (“small” countries) for example, the territory is practically entirely covered by points, that is, there are a high incidence of earthquakes in these 2 countries. Each dot represents an earthquake. It also caught my attention that there is a region in Nicaragua that had 27 earthquakes in 2023, which is a lot!
I started researching and discovered that one of the reasons why Indonesia suffers from large amounts of earthquakes is because it is located at the meeting of 5 tectonic plates that are active. Earthquakes occur daily (usually magnitude 5). The country was devastated by the earthquake (followed by a tsunami) in 2004. It recorded the highest magnitude ever, 9.3, and the longest duration ever seen (approximately 10 minutes). Japan, in turn, suffered a terrible tsunami in 2011 (magnitude scale 9.0). The epicenter of the earthquake occurred 80km northeast of the city of Tohoku. The waves formed by the tsunami reached 40 meters and advanced 10km towards the continent. More than 18 thousand people died and thousands more were injured. Japan is located in an area known as the “Pacific Ring of Fire, where it lies across three tectonic plates, including the Pacific Plate under the Pacific Ocean and the Philippine Sea Plate.”Another subject that aroused my curiosity was the San Andreas fault, whose origin was in 1906 in an earthquake that killed more than 3000 people. There is concern that the rupture will increase and cause more harm to the population of California, but no scientist can pinpoint when or how this failure will worsen.
I would like to have made a map but with areas in red according to the degree of earthquake incidence, that is, the redder it is, the more likely that area is to have earthquakes. The visualizations revealed interesting things to me, such as the fact that Central America is a place where there are many earthquakes - even of low magnitude. I did not know that.
Pribadi, K. Suryanto, and D. K. Rildova. “Learning from recent Indonesian earthquakes: An overview to improve structural performance.” 14th world conference on earthquake engineering, Beijing, China. 2008.
Ando, Shuntaro, et al. “Mental health problems in a community after the Great East Japan Earthquake in 2011: a systematic review.” Harvard review of psychiatry 25.1 (2017): 15-28
Hale, Tom. “Why We Need to Pay Attention to the San Andreas Fault.” IFLScience, 13 Oct. 2023, www.iflscience.com/why-we-need-to-pay-attention-to-the-san-andreas-fault-71115.