Created
November 28, 2021 02:22
-
-
Save dakvid/6fd016460c1ce3851ba8b1559b21f2fd to your computer and use it in GitHub Desktop.
#30DayMapChallenge 2021 - Day 27 - Heatmap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a (not very good) heatmap of earthquakes in New Zealand | |
# For #30DayMapChallenge 2021 - Day 27 - Heatmap | |
# -- David Friggens, November 2021 | |
# Setup ------------------------------------------------------------------- | |
library(readr) | |
library(dplyr) | |
library(sf) | |
library(rnaturalearth) | |
library(ggplot2) | |
library(ggmap) | |
# Data -------------------------------------------------------------------- | |
# from https://quakesearch.geonet.org.nz | |
eq <- | |
read_csv("data/earthquakes.csv") %>% | |
filter(eventtype == "earthquake") %>% | |
select(longitude, latitude, magnitude) | |
geo_eq <- | |
eq %>% | |
st_as_sf(coords = c("longitude", "latitude"), crs = 4326L) | |
eq_d1 <- | |
eq %>% | |
mutate(longitude = round(longitude, 1), | |
latitude = round(latitude, 1)) %>% | |
group_by(longitude, latitude) %>% | |
summarise(magnitude = sum(magnitude)) %>% | |
ungroup() | |
nz <- | |
ne_countries(scale = "small", returnclass = "sf") %>% | |
filter(iso_a3 == "NZL") | |
# Plot -------------------------------------------------------------------- | |
gg_eq <- | |
ggmap(get_stamenmap(bbox = c(164, -48, 181.3, -33.8), | |
zoom = 6, | |
maptype = "watercolor")) + | |
stat_density_2d(data = eq, | |
aes(x = longitude, y = latitude, | |
fill = ..level..), | |
geom = "polygon", | |
alpha = 0.3, colour = NA) + | |
scale_fill_viridis_c() + | |
theme_void() + | |
theme(legend.position = "none") | |
ggsave(plot = gg_eq, | |
"Day_27/Day_27_wc_eq.png", | |
width = 20, height = 20, dpi = 72) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment