Skip to content

Instantly share code, notes, and snippets.

@fanghuiz
Created September 23, 2019 22:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fanghuiz/1269ee42d11802a471712ef0599be107 to your computer and use it in GitHub Desktop.
Save fanghuiz/1269ee42d11802a471712ef0599be107 to your computer and use it in GitHub Desktop.
Animated map showing daily active fires in Indonesia this September
# Set up
library(ggplot2)
library(dplyr)
library(ggmap)
library(maps)
library(gganimate)
# Request raw data from https://firms.modaps.eosdis.nasa.gov/active_fire/#firms-txt
# Data used for this map
url <- "https://raw.githubusercontent.com/fanghuiz/random_viz/master/data/fire_IND_201909.csv"
fire <- readr::read_csv(url)
# Find boundaries of Indonesia, to be used to download map tiles
# I used this to help https://tools.geofabrik.de/calc/
idn_bbox <- c(left=94.77, bottom=-11.21, right=141.03, top=6.28)
# Download map tiles
idn_map <- get_stamenmap(
idn_bbox,
zoom = 6,
maptype = "toner-lite") %>%
ggmap()
caption <- glue::glue(
"Active fire data from LANCE FIRMS operated by NASA's Earth Science Data and Information System (ESDIS)
Dataset used: MODIS Collection 6 NRT Hotspot / Active Fire Detections MCD14DL.
Available on-line at https://earthdata.nasa.gov/firms")
# Create the static base map
p <- idn_map +
# Add borders to the base map
borders(regions = "indonesia", colour = "gray20", fill = "transparent") +
geom_point(data = fire,
aes(x = longitude, y = latitude, group = acq_date),
alpha = 0.3, color = "tomato") +
hrbrthemes::theme_ipsum_rc() +
theme(axis.line = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank())
# Add animation
p +
transition_time(acq_date) +
enter_fade() +
exit_fade() +
shadow_wake(wake_length = 0.1) +
labs(title = "Active Fires in Indonesia (2019 September)",
subtitle = "Date: {frame_time}",
caption = caption,
x = "", y = "") +
animate(p, duration = 30, end_pause = 10, width = 800, height = 500)
anim_save("indonesia_fire.gif")
@fanghuiz
Copy link
Author

indonesia_fire

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment