Skip to content

Instantly share code, notes, and snippets.

@batpigandme
batpigandme / visdat_review.md
Last active January 24, 2017 13:14
Copy of ropensci reviewer template for use in reviewing package. Original source: https://github.com/ropensci/onboarding/blob/master/reviewer_template.md

Package Review

Please check off boxes as applicable, and elaborate in comments below. Your review is not limited to these topics, as described in the reviewer guide

  • As the reviewer I confirm that there are no conflicts of interest for me to review this work (such as being a major contributor to the software).

Documentation

The package includes all the following forms of documentation:

@batpigandme
batpigandme / nba1617_preseason_team_summary.R
Last active October 25, 2016 20:39
Get summary statistics for each NBA team in the 2016-17 NBA season
##################################
## Getting Team Preseason Stats ##
##################################
## set strings as factors to false
options(stringsAsFactors = FALSE)
## load libraries
library(stattleshipR)
library(dtplyr)
@batpigandme
batpigandme / steph_gls_stattleship_retrieval.R
Last active August 29, 2016 13:01
Retrieve nba-stephen-curry game logs from stattleship API.
## install and load the stattleshipR package
devtools::install_github("stattleship/stattleship-r")
library(stattleshipR)
## optional: load dplyr
library(dplyr)
## get your API token stattleship.com
## set API token
set_token('YOUR API TOKEN')
@batpigandme
batpigandme / summary_threes_curry_gls.txt
Last active February 25, 2016 16:33
nba-stephen-curry summary of three point stats
│ three_pointers_attempted │ three_pointers_made │ three_pointers_pct │
├──────────────────────────┼─────────────────────┼────────────────────┤
│ Min. : 4.00 │ Min. : 1.000 │ Min. :0.1110 │
│ 1st Qu.: 9.00 │ 1st Qu.: 3.000 │ 1st Qu.:0.3407 │
│ Median :11.00 │ Median : 5.000 │ Median :0.4550 │
│ Mean :10.81 │ Mean : 4.926 │ Mean :0.4401 │
│ 3rd Qu.:13.00 │ 3rd Qu.: 7.000 │ 3rd Qu.:0.5000 │
│ Max. :16.00 │ Max. :11.000 │ Max. :0.7330 │
@batpigandme
batpigandme / curry_three_pointers_base_ggplot.R
Last active February 25, 2016 15:14
EDA with density plot and histograms of nba-stephen-curry three point shooting, base R, and with ggplot2 and ggthemes
## steph curry's three-point shooting data from
## stattleship api
## density plot of three-pt pctg
d <- density(steph_gls$three_pointers_pct)
plot(d, type="n", main="three point percentage")
polygon(d, col="red", border="gray")
## histograms
hist(steph_gls$three_pointers_attempted)
@batpigandme
batpigandme / steph_curry_3ptpct_densityplot.R
Created February 24, 2016 18:37
Make a density plot of Steph Curry's three point percentages so far this season by game.
d3pct <- density(steph_gls$three_pointers_pct)
plot(d3pct)
@batpigandme
batpigandme / stattle_nba_point_leads_sm_multiples.R
Last active January 29, 2016 15:23
Different ways of visualizing team point leads and outcomes using small multiples.
## visualize team point leads and outcomes with small multiples
## install and load ggplot2
install.packages("ggplot2")
library(ggplot2)
## make separate point plots for each team
ggplot(teamgame_point_leads, aes(x=final_point_diff, y=points_biggest_lead)) + geom_point() +
facet_wrap(~team_slug)
@batpigandme
batpigandme / opponent_team_lead_table_plus_summary.R
Last active January 29, 2016 17:12
Match opponent leads to team game logs and select variables for new, focused data table, as well as a summary table for each team.
## set keys for the data table on game_slug and opponent_slug
team_game_logs <- setkey(team_game_logs, game_slug, opponent_slug)
## get opponent leads by matching on both key columns
team_game_logs$opp_biggest_lead <- team_game_logs[. (team_game_logs$game_slug, team_game_logs$opponent_slug)]$points_biggest_lead
## set keys for the data table on game_slug and opponent_slug
team_game_logs <- setkey(team_game_logs, game_slug, opponent_slug)
## get opponent leads by matching on both key columns
@batpigandme
batpigandme / team_game_logs_for_lead_post.R
Last active August 29, 2016 13:01
Get and load team game logs from Stattleship API. Assumes you've retrieved teams, if not, see: https://gist.github.com/batpigandme/d06f279369546dbfe462
## load the stattleshipR and dplyr packages
library(stattleshipR)
library(dplyr)
## set params for team_game_logs
sport <- "basketball"
league <- "nba"
ep <- "team_game_logs"
## leave q_body empty to get all
@batpigandme
batpigandme / nba_team_retrieval.R
Last active August 29, 2016 12:59
Retrieve NBA teams using Stattleship API
## install and load the stattleshipR package
devtools::install_github("stattleship/stattleship-r")
library(stattleshipR)
## get API token at playbook.stattleship.com
## set API token
set_token('YOUR_ACCESS_TOKEN')
## set up envt
options(stringsAsFactors=FALSE)