Libraries / packages
This post is just a continuation of the previous post on interactive maps. In this occasion we will add a slider to our map, map created again using {ggplot2} and {plotly}, that will help us to display the evolution of data over time.
library(tidyverse)
library(gganimate)
library(ggthemes)
library(plotly)
Meteorites dataset
world <- map_data("world") %>%
filter(region != "Antarctica")
meteoritos <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-06-11/meteorites.csv")
options(scipen = 999)
meteoritos_Mundo <- meteoritos %>%
filter(fall == "Fell") %>%
filter(year > 1980) %>%
drop_na() %>%
arrange(mass)
Example 2.
mapa_animado_2 <- world %>%
ggplot() +
geom_polygon(aes( x= long, y = lat, group = group),
fill = "grey20",
color = "white",
size = 0.01) +
geom_point(data= meteoritos_Mundo,
aes(x = long,
y = lat,
frame = year,
size = mass),
color = "orange",
alpha = 0.7) +
labs( title = "Meteorite Landings \n from 1980 to 2013}",
caption = "The Meteoritical Society") +
theme_map() +
scale_size_continuous(guide = F) +
scale_color_discrete(name = "Type") +
theme(plot.title = element_text(size = 10, hjust = 0.5))
fig_2 <- ggplotly(mapa_animado_2) %>% animation_slider(currentvalue = list(prefix = "Year ", font = list(color="orange")))
fig_2
If you can not see the plot click here