Analyzing Twitch data

Analyzing Twitch data

May 5, 2020

## Loading required package: RMySQL
## Loading required package: DBI
## Loading required package: dplyr
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## Loading required package: ggplot2
## Loading required package: ggdark
## Loading required package: ggiraph
## Loading required package: stringr
## Loading required package: lubridate
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:dplyr':
## 
##     intersect, setdiff, union
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
## Loading required package: highcharter
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
## Highcharts (www.highcharts.com) is a Highsoft software product which is
## not free for commercial and Governmental use
## [1] "df2"       "snapshots"
## Warning: Missing values are always removed in SQL.
## Use `mean(x, na.rm = TRUE)` to silence this warning
## This warning is displayed only once per session.
g <- ggplot(df, aes(x = reorder(game_name, avg_viewer_count), y = avg_viewer_count)) + 
  geom_bar_interactive(stat = 'identity', aes(tooltip = avg_viewer_count, data_id = str_replace_all(game_name, "'", ""))) + 
  xlab('') + ylab('Average Viewer Count') + 
  labs(caption = 'Source: data.basement.org; Twitch API') +
  ggtitle('Most viewed games on Twitch') +
  coord_flip() + 
  dark_theme_minimal() + 
  theme(text = element_text(size = 9), 
        plot.title.position = 'plot',
        plot.caption.position = 'plot',
        plot.caption = element_text(size = 6, hjust = 0)) 
## Inverted geom defaults of fill and color/colour.
## To change them back, use invert_geom_defaults().
ggiraph::ggiraph(ggobj = g, height_svg = 3.5)
g <- ggplot(df2, aes(x = Period, y = game_name)) + 
  geom_tile_interactive(aes(fill = viewer_count, tooltip = viewer_count, data_id = Period)) + 
#  xlab('') + ylab('Average Viewer Count') + 
#  labs(caption = 'Source: data.basement.org; Twitch API') +
  ggtitle('Most viewed games on Twitch') +
  dark_theme_minimal() + 
  theme(text = element_text(size = 9), 
        plot.title.position = 'plot',
        plot.caption.position = 'plot',
        plot.caption = element_text(size = 6, hjust = 0)) +
  scale_fill_viridis_c_interactive('total views per hour', option = 'inferno')


gg <- ggiraph::ggiraph(ggobj = g, height_svg = 3.5)
gg <- girafe_options(gg, opts_toolbar(position = 'top'))

gg