Skip to content

Instantly share code, notes, and snippets.

@Sandy4321
Forked from abresler/xy_plot_example.r
Created December 18, 2015 15:12
Show Gist options
  • Save Sandy4321/4465e09fb9a349bf2e15 to your computer and use it in GitHub Desktop.
Save Sandy4321/4465e09fb9a349bf2e15 to your computer and use it in GitHub Desktop.
XY ggplot using nbastatR
library("devtools")
install_github(c("hadley/ggplot2", "jrnold/ggthemes", "abresler/nbastatR"))
packages <-
c('nbastatR', 'dplyr', 'magrittr', 'ggthemes', 'ggplot2')
lapply(packages, library, character.only = T)
teams2015 <-
get_all_team_traditional_stat_tables(year.season_start = 2015)
teams2015 %>%
ggplot(aes(
pct.fga3a,
pct.wins,
label = slug.team,
color = factor(ortg <= 100)
),
alpha = .4) +
geom_text(check_overlap = T) +
geom_smooth(
se = F,
show.legend = F,
alpha = .4,
size = .5
) +
geom_vline(
xintercept = mean(teams2015$pct.fga3a),
size = .5,
linetype = 2
) +
geom_hline(
yintercept = mean(teams2015$pct.wins),
size = .5,
linetype = 2
) +
theme_hc() +
scale_color_fivethirtyeight(guide = guide_legend(title = "Offensive Rating\n<=100"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment