```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r message = FALSE}
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`

```{r}
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)
```

## Creating Animated Figures using `gganimate`

```{r}
p1_anim <- p1 + 
  transition_reveal(year)
animate(p1_anim)
anim_save("time-series-gif-example.gif")
```




