This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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) { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
song_data %>% | |
unnest() %>% | |
unnest_tokens(word, lyric) %>% | |
anti_join(stop_words, by = "word") |
NewerOlder