Skip to content

Instantly share code, notes, and snippets.

@eoppe1022
eoppe1022 / my_tweets_chart.R
Created March 11, 2019 02:12
Tweets Chart
library(rtweet)
library(dplyr)
library(ggplot2)
library(extrafont)
theme_awesome <- function(font) {
theme_minimal() +
theme(plot.title = element_text(hjust = 0, face = "bold", family = font, size = 45, margin = margin(1, 0, 20, 0)),
@eoppe1022
eoppe1022 / CHL Box Score Scraper.R
Last active February 10, 2019 18:55
CHL Box Score Scraper
library(tidyverse) #install.packages("tidyverse")
library(rvest) #install.packages("rvest")
library(RSelenium) #install.packages("RSelenium")
library(progress) #install.packages("progress")
## 2 functions: get_schedule() and get_box_score()
## Some things are a bit iffy but it should work
## Gets schedule. You need this
## Example: get_schedule("WHL", "2018-19")
@eoppe1022
eoppe1022 / New Alluvial Player Points Charts.R
Last active November 21, 2019 01:31
New Alluvial Player Points Charts
## Let goal_data be a data frame with (at least) columns "goal", "primary_assist", "secondary_assist", and "team"
library(tidyverse)
library(ggfittext)
library(ggalluvial)
library(extrafont)
## The theme for the chart
theme_awesome <- function(font) {
@eoppe1022
eoppe1022 / Alluvial Charts.R
Last active February 6, 2019 03:11
Alluvial Charts
library(tidyverse)
library(extrafont)
library(ggalluvial)
## Custom Font
theme_awesome <- function(font) {
theme_minimal(base_family = font) +
theme(plot.title = element_text(hjust = 0.5, face = "bold", size = 50, margin = margin(1, 0, 20, 0)),
@eoppe1022
eoppe1022 / Betweenness (Fair).R
Last active October 28, 2021 00:58
Calculating Betweenness (Only in Each Player's Games)
## calculates betweenness (with igraph::betweenness()) for each player on each team for each season and each league in only the games that each player played in
## mydata$game_info is a data frame, where each row is a different game
## the columns are my_season (different seasons), my_league (NHL or CHL or whatever), my_team (NYR or whatever), home_team, away_team, ...
## ... home_skater_names (every skater on the home team separated by a "|"), away_skater_names, ...
## ... and goals (a nested data frame that has a column for team, season, league, game strength, goal scorer, primary assister, and secondary assister
## i also have a data frame mydata$goals that has columns for team, season, league, game strength, goal scorer, primary assister, and secondary assister
library(tidyverse)
library(igraph)
@eoppe1022
eoppe1022 / Count Angry Lyrics Death Grips Anger.R
Created January 26, 2019 17:51
Count Angry Lyrics Death Grips Anger
song_data %>%
unnest() %>%
unnest_tokens(word, lyric) %>%
anti_join(stop_words, by = "word") %>%
left_join(angry_words, by = "word") %>%
group_by(track_name, energy, album_name, duration_ms, valence) %>%
summarize(angry_words = sum(anger, na.rm = TRUE)) %>%
ungroup() %>%
select(track_name, album_name, angry_words) %>%
arrange(desc(angry_words))
@eoppe1022
eoppe1022 / Death Grips Sonic Anger Index.R
Last active January 28, 2019 05:45
Death Grips Sonic Anger Index
library(scales)
song_data %>%
unnest() %>%
unnest_tokens(word, lyric) %>%
anti_join(stop_words, by = "word") %>%
left_join(angry_words, by = "word") %>%
group_by(track_name, energy, album_name, duration_ms, valence) %>%
summarize(percent_angry = sum(anger, na.rm = TRUE) / n(), word_count = n()) %>%
ungroup() %>%
@eoppe1022
eoppe1022 / Death Grips Lyrical Anger Index.R
Last active January 28, 2019 05:44
Death Grips Lyrical Anger Index
library(scales)
song_data %>%
unnest() %>%
unnest_tokens(word, lyric) %>%
anti_join(stop_words, by = "word") %>%
left_join(angry_words, by = "word") %>%
group_by(track_name, energy, album_name, duration_ms, valence) %>%
summarize(percent_angry = sum(anger, na.rm = TRUE) / n(), word_count = n()) %>%
ungroup() %>%
@eoppe1022
eoppe1022 / Death Grips Anger Percent Angry.R
Created January 24, 2019 04:52
Death Grips Anger Percent Angry
song_data %>%
unnest() %>%
unnest_tokens(word, lyric) %>%
anti_join(stop_words, by = "word") %>%
left_join(angry_words, by = "word") %>%
group_by(track_name, energy, album_name, duration_ms, valence) %>%
summarize(percent_angry = sum(anger, na.rm = TRUE) / n(), word_count = n()) %>%
ungroup() %>%
select(track_name, album_name, percent_angry) %>%
arrange(desc(percent_angry))
@eoppe1022
eoppe1022 / Death Grips Anger Removing Stop Words.R
Created January 24, 2019 04:48
Death Grips Anger Removing Stop Words
song_data %>%
unnest() %>%
unnest_tokens(word, lyric) %>%
anti_join(stop_words, by = "word")