# Load necessary libraries
pacman::p_load(pacman, readr, ggplot2, maps, mapdata)
# Load the CSV file
earthquake_1995_2023 <- read_csv("earthquake_data.csv")
## Rows: 782 Columns: 19
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (8): title, date_time, alert, net, magType, location, continent, country
## dbl (11): magnitude, cdi, mmi, tsunami, sig, nst, dmin, gap, depth, latitude...
##
## ℹ 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.
# Basic World Map using ggplot2
world_map <- map_data("world")
# Create a plot
ggplot() +
# Draw the world map with green land
geom_polygon(data = world_map, aes(x = long, y = lat, group = group),
fill = "#66cc33", color = "#666666") +
# Plot earthquake data points
geom_point(data = earthquake_1995_2023,
aes(x = longitude, y = latitude, size = magnitude, color = depth),
alpha = 0.6) +
# Customise size scale
scale_size_continuous(name = "Magnitude", range = c(1, 5)) +
# Customise colour scale for depth
scale_color_gradient(name = "Depth (km)", low = "#ffff99", high = "#cc0033") +
# Add labels and title
labs(title = "Earthquakes from 2001 to 2022",
x = "Longitude",
y = "Latitude") +
# Set theme
theme() +
# Map appearance
theme(panel.background = element_rect(fill = "#99ccff"), # Blue water
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.background = element_rect(fill = "#cccccc")) # grey plot background
