Introduction

In this vignette we observe how plotly can be used to animate plots which can be a great way to visualize changes in a dataset. Here i use it to visualize changes in genres of the top selling games across the years 2000 to 2015. You can either click play to automatically run through the years, or use the slider.

library(plotly)
library(dplyr)


vgsales <- read.csv("https://raw.githubusercontent.com/jerryjerald27/Data-607/refs/heads/main/Tidyverse/vgsales.csv")

vgsales_filtered <- vgsales %>% filter(Year >= 2000 & Year <= 2015)

plot_ly(data = vgsales_filtered, 
        x = ~Global_Sales, 
        y = ~Genre, 
        color = ~Genre, 
        frame = ~Year, 
        type = 'bar', 
        orientation = 'h', 
        marker = list(line = list(width = 10))) %>%
  layout(
    xaxis = list(title = 'Global Sales (millions)'),
    yaxis = list(title = 'Game Genre'),
    title = 'Top Selling Game Genres (2000 to Present)',
    updatemenus = list(
      list(
        type = 'buttons',
        showactive = FALSE,
        buttons = list(
          list(method = 'animate', args = list(NULL, list(frame = list(duration = 1000, redraw = TRUE), mode = 'immediate')))
        )
      )
    )
  )

Additional Analysis by Mohammad Zahid Chowdhury.

This is a collaborative work. The initial analysis done by Jerald Melukkaran and I did some descriptive analysis.I dowloaded this rmd file from Github and did some descriptive analysis. I also submitted my Github handle.

Top-Selling Genres Overall (2000–2015):

vgsales_filtered %>%
  group_by(Genre) %>%
  summarise(Total_Sales = sum(Global_Sales, na.rm = TRUE)) %>%
  arrange(desc(Total_Sales))
## # A tibble: 12 × 2
##    Genre        Total_Sales
##    <chr>              <dbl>
##  1 Action             1512.
##  2 Sports             1116.
##  3 Shooter             879.
##  4 Misc                724.
##  5 Role-Playing        717.
##  6 Racing              563.
##  7 Platform            496.
##  8 Simulation          337.
##  9 Fighting            310.
## 10 Adventure           183.
## 11 Puzzle              140.
## 12 Strategy            116.

Yearly Top Genre:

vgsales_filtered %>%
  group_by(Year, Genre) %>%
  summarise(Yearly_Sales = sum(Global_Sales, na.rm = TRUE)) %>%
  slice_max(Yearly_Sales, n = 1)
## `summarise()` has grouped output by 'Year'. You can override using the
## `.groups` argument.
## # A tibble: 16 × 3
## # Groups:   Year [16]
##    Year  Genre  Yearly_Sales
##    <chr> <chr>         <dbl>
##  1 2000  Sports         41.2
##  2 2001  Action         59.4
##  3 2002  Action         86.8
##  4 2003  Action         67.9
##  5 2004  Action         76.3
##  6 2005  Action         85.7
##  7 2006  Sports        136. 
##  8 2007  Action        106. 
##  9 2008  Action        136. 
## 10 2009  Action        139. 
## 11 2010  Action        118. 
## 12 2011  Action        119. 
## 13 2012  Action        122. 
## 14 2013  Action        125. 
## 15 2014  Action         99.0
## 16 2015  Action         70.7
vgsales_filtered %>%
  group_by(Publisher) %>%
  summarise(Total_Sales = sum(Global_Sales)) %>%
  arrange(desc(Total_Sales)) %>%
  slice_head(n = 10)
## # A tibble: 10 × 2
##    Publisher                    Total_Sales
##    <chr>                              <dbl>
##  1 Nintendo                           1181.
##  2 Electronic Arts                     996.
##  3 Activision                          673.
##  4 Ubisoft                             455.
##  5 Sony Computer Entertainment         429.
##  6 Take-Two Interactive                387.
##  7 THQ                                 321.
##  8 Microsoft Game Studios              239.
##  9 Sega                                222.
## 10 Konami Digital Entertainment        221.