library(tidyverse)
library(gapminder)
library(ggthemes)
# you need to install gifski, transformr, and png along with gganimate
library(gganimate)
library(plotly)
Interactive Plot using plotly
chosen_countries <- c("Philippines", "United States", "Japan")
df <- gapminder %>%
# get only the chosen countries
filter(country %in% chosen_countries) %>%
# drop any rows with missing values
drop_na()
# overlayed time-series plot
p1 <- ggplot(data = df, aes(x = year, y = gdpPercap, color = country)) +
geom_point() +
geom_line() +
scale_colour_colorblind() +
labs(x = "year",
y = "GDP per Capita",
title = "Yearly GDP per Capita")
ggplotly(p1)