Libraries / packages
This post is just a continuation of the previous post on animated and interactive maps. We will show four examples of maps created using {ggplot2} and {plotly}.
library(tidyverse)
library(gapminder)
library(echarts4r)
library(gganimate)
library(ggiraph)
library(widgetframe)
library(ggthemes)
library(plotly)
library(viridis)
library(DT)
Datasets
gapminder dataset:
world <- map_data("world") %>%
filter(region != "Antarctica")
gapminder_codes <- gapminder::country_codes
gapminder <-gapminder::gapminder_unfiltered
gapminder <- gapminder %>%
inner_join(gapminder_codes, by= "country") %>%
mutate(code = iso_alpha)
gapminder_data <- gapminder %>%
inner_join(maps::iso3166 %>%
select(a3, mapname), by= c(code = "a3")) %>%
mutate(mapname = str_remove(mapname, "\\(.*"))
Meteorites dataset
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 > 1800) %>%
drop_na() %>%
arrange(mass)
Example 1.
mapa_animado_1 <- 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,
size = mass),
color = "orange",
alpha = 0.7) +
labs( title = "Meteorite Landings \n from 1800 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_1 <- ggplotly(mapa_animado_1)
fig_1