The purpose of this analysis is to explore the distribution, intensity, and depth of earthquakes across different countries in select regions using real-world data. This analysis aims to uncover regional patterns, identify high-risk zones, and visualize the relationship between magnitude and depth, supporting better understanding of seismic behavior.
This is a structured sample dataset modeled after global earthquake data, used for learning and skill demonstration.
# Load all necessary packages
library(tidyverse)
# Import and name dataset
earthquakes <- read_csv("earthquakes_sample_dataset.csv")
glimpse(earthquakes)
# Group into regions
# Define a function to categorize countries into regions
categorize_region <- function(country) {
if (country %in% c("California", "Mexico", "Chile", "Peru")) {
return("Americas")
} else if (country %in% c("Japan", "Indonesia", "China", "Nepal")) {
return("Asia")
} else if (country %in% c("Italy", "Greece", "Turkey")) {
return("Europe")
} else if (country %in% c("New Zealand", "Australia")) {
return("Oceania")
} else {
return("Middle East")
}
}
# Apply the function to create a new column 'Region'
earthquakes <- earthquakes %>%
mutate(Region = lapply(Country, categorize_region)) %>%
arrange(desc(Magnitude))
earthquakesFrom the restructured table above, the country with the lowest magnitude (4) is Turkey and it took place on August 8, 2021.
# Filter for regions with the highest magnitudes
major_quakes <- earthquakes %>%
filter(Magnitude >= 6) %>%
arrange(desc(Magnitude))
major_quakesFrom the Major Earthquakes table above, Japan and New Zealand have the highest earthquake magnitudes (8.9) which occurred at a 7-year interval (January 6, 2010 and June 6, 2003 respectively) with the most recent being Japan.
# Average Earthquakes by region
earthquakes %>%
group_by(Region) %>%
summarise(avg_magnitude = mean(Magnitude)) %>%
arrange(desc(avg_magnitude))From the average magnitude table above, the region with the most high-magnitude events is Oceania (6.975).
# Number of Earthquakes per Country (Visualization)
earthquakes %>%
count(Country) %>%
ggplot(aes(x = reorder(Country, -n), y = n)) +
geom_bar(stat = "identity", fill = "steelblue") +
labs(title = "Earthquakes Per Country", x = "Country", y = "Count") +
theme_minimal()
From the Bar chart above, California has the highest number of earthquake occurences (16) and Nepal has the lowest occurences (4).# Magnitude Versus Depth
ggplot(earthquakes, aes(x = Depth_km, y = Magnitude)) +
geom_point(aes(color = Country), alpha = 0.6) +
labs(title = "Magnitude vs Depth", x = "Depth(km)", y = "Magnitude") +
theme_grey()From the scatter plot above, it can be said that the magnitude of an earthquake plays a minimal role in its depth determination.