q1 <- gapminder %>% 
  group_by(continent) %>% 
  summarize(averageGDP = mean(gdpPercap), 
            maxGDP = max(gdpPercap))
q1
## # A tibble: 5 × 3
##   continent averageGDP  maxGDP
##   <fct>          <dbl>   <dbl>
## 1 Africa         2194.  21951.
## 2 Americas       7136.  42952.
## 3 Asia           7902. 113523.
## 4 Europe        14469.  49357.
## 5 Oceania       18622.  34435.
static_plot <- plot_ly(gapminder, x = ~gdpPercap, y =~lifeExp, color = ~continent, 
                       size = ~pop, type = "scatter", mode = "markers", marker = list(sizemode = "diameter")) %>% 
  layout(title = "Life Expectancy vs. GDP per Capita in 2007",
         xaxis = list(title = "GDP per Capita"),
         yaxis = list(title = "Life Expectancy"))
animated_plot <- plot_ly(gapminder, x = ~gdpPercap, y =~lifeExp, color = ~continent, 
                       size = ~pop, frame =~ year, type = "scatter", mode = "markers", marker = list(sizemode = "diameter")) %>% 
  layout(title = "Life Expectancy vs. GDP per Capita in 2007",
         xaxis = list(title = "GDP per Capita"),
         yaxis = list(title = "Life Expectancy"))
animated_plot
  1. Frame is the amount of time between frames in milliseconds. Easing is the type of linear easing. Redraw decides whether you redraw the plot at completion of the transition
animated_chart <- animated_plot %>% 
  animation_opts(frame = 100,  
                 redraw = TRUE, 
                 easing = "linear")
animated_chart
interactive_chart <- animated_chart %>% layout(
  updatemenus = list(
    list(
      type = "buttons",
      showactive = FALSE,
      x = 0,
      y = 0,
      buttons = list(

        list(
          label = "Pause",
          method = "animate",
          args = list(NULL, list(frame = list(duration = 0,
                                              redraw = TRUE),
                                 mode = "immediate"))
        )
      )
    )
  )
)
interactive_chart
  1. I included the country within the hovering labels so you know which country it is.
animated_plot_updated <- plot_ly(gapminder, x = ~gdpPercap, y =~lifeExp, color = ~continent, 
                       size = ~pop, frame =~ year, text =~ country, type = "scatter", mode = "markers", marker = list(sizemode = "diameter")) %>% 
  layout(title = "Life Expectancy vs. GDP per Capita in 2007",
         xaxis = list(title = "GDP per Capita"),
         yaxis = list(title = "Life Expectancy"))
animated_plot_updated
  1. Done on Rpubs