Giter Site home page Giter Site logo

nflverse / nflplotr Goto Github PK

View Code? Open in Web Editor NEW
18.0 2.0 1.0 433.34 MB

A set of functions to visualize National Football League analysis in 'ggplot2'

Home Page: https://nflplotr.nflverse.com

License: Other

R 99.50% CSS 0.50%
cran cran-r nfl r-package nflstats nflfastr nflverse sportsanalytics sports-analytics

nflplotr's Introduction

nflverse

CRAN status Dev status R-CMD-check nflverse support

Overview

The nflverse is a set of packages dedicated to data of the National Football League. The nflverse package is designed to make it easy to install and load core packages from the nflverse in a single command. Please see the nflverse organisation repo on more information about governance, the code of conduct and possible roles.

Installation

The easiest way to get nflverse is to install it from CRAN with:

install.packages("nflverse")

To get a bug fix or to use a feature from the development version, you can install the development version of nflverse either from GitHub with:

if (!require("pak")) install.packages("pak")
pak::pak("nflverse/nflverse")

or prebuilt from the development repo with:

install.packages("nflverse", repos = c("https://nflverse.r-universe.dev", getOption("repos")))

Usage

library(nflverse) will load the following nflverse packages:

  • nflfastR, for play-by-play data back to 1999.
  • nflseedR, for season simulations.
  • nfl4th, for 4th down analysis.
  • nflreadr, for fast end efficient nflverse data downloads.
  • nflplotR, for tools to create visualization of NFL related analysis.

Getting help

The best places to get help on this package are:

Contributing

Many hands make light work! Here are some ways you can contribute to this project:

Terms of Use

The R code for this package is released as open source under the MIT License. NFL data accessed by this package belong to their respective owners, and are governed by their terms of use.

nflplotr's People

Contributors

mrcaseb avatar spatto12 avatar tanho63 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

spatto12

nflplotr's Issues

Missing element_nfl_logo when changing scale position

Hi!

Maybe I'm doing something wrong, but I can't seem to be able to replace team names for logos when you move the X axis to the top with nflplotR::element_nfl_logo

This is some small example:

example <- data.frame(
  week = c(1, 2, 3),
  tm_opp_team = c("KC", "LV", "LA"),
  snap_total = c(47, 18, 50)
)

ggplot2::ggplot(example,aes(x=tm_opp_team,y=snap_total,))+
  geom_point()+
  ggplot2::scale_x_discrete(position="top")+
  ggplot2::theme(axis.text.x  = nflplotR::element_nfl_logo())

image

If you let the X on the bottom or remove the nfl_logo element they show up correctly

ggplot2::ggplot(example,aes(x=tm_opp_team,y=snap_total,))+
  geom_point()+
  ggplot2::scale_x_discrete()+
  ggplot2::theme(axis.text.x  = nflplotR::element_nfl_logo())

ggplot2::ggplot(example,aes(x=tm_opp_team,y=snap_total,))+
  geom_point()+
  ggplot2::scale_x_discrete(position="top")

image
image


This was the nflplotR version I used: 
> nflverse::nflverse_sitrep("nflplotR")
── System Info ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• R version 4.2.1 (2022-06-23 ucrt)   • Running under: Windows 10 x64 (build 19043)
── nflverse Packages ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• nflplotR (1.1.0)
── nflverse Options ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
No options set for nflplotR
── nflverse Dependencies ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• cachem     (1.0.6)   • labeling  (0.4.2)     • pkgconfig    (2.0.3)  
• cli        (3.4.1)   • lattice   (0.20-45)   • R6           (2.5.1)  
• colorspace (2.0-3)   • lifecycle (1.0.2)     • rappdirs     (0.3.3)  
• curl       (4.3.2)   • magick    (2.7.3)     • RColorBrewer (1.1-3)  
• data.table (1.14.2)  • magrittr  (2.0.3)     • Rcpp         (1.0.9)  
• digest     (0.6.29)  • MASS      (7.3-58.1)  • rlang        (1.0.6)  
• fansi      (1.0.3)   • Matrix    (1.5-1)     • scales       (1.2.1)  
• farver     (2.1.1)   • memoise   (2.0.1)     • tibble       (3.1.8)  
• fastmap    (1.1.0)   • mgcv      (1.8-40)    • utf8         (1.2.2)  
• ggplot2    (3.3.6)   • munsell   (0.5.0)     • vctrs        (0.4.1)  
• glue       (1.6.2)   • nflreadr  (1.3.1)     • viridisLite  (0.4.1)  
• gtable     (0.3.1)   • nlme      (3.1-159)   • withr        (2.5.0)  
• isoband    (0.2.5)   • pillar    (1.8.1)  

Release nflplotR 1.0.1

Prepare for release:

  • Check current CRAN check results
  • Polish NEWS
  • devtools::build_readme()
  • urlchecker::url_check()
  • usethis::use_version('patch')
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • devtools::check_mac_release()
  • rhub::check_for_cran(show_status = FALSE)
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md

Submit to CRAN:

  • devtools::release()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version()

Release nflplotR 1.1.0

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Check if any deprecation processes should be advanced, as described in Gradual deprecation
  • Polish NEWS
  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md
  • git push
  • Draft blog post

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • git push
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • git push
  • Finish blog post
  • Tweet
  • Add link to blog post in pkgdown news menu

scale_y_nfl() fails

Describe the bug
scale_y_nfl() returns the warning below and then makes the graph without a y-axis instead of with the logos.

Reprex
This is the example for scale_x_nfl() with all the x's and y's switched

library(nflplotR)
library(ggplot2)

team_abbr <- valid_team_names()
# remove conference logos from this example
team_abbr <- team_abbr[!team_abbr %in% c("AFC", "NFC")]

df <- data.frame(
  random_value = runif(length(team_abbr), 0, 1),
  teams = team_abbr
)

ggplot(df, aes(y = teams, x = random_value)) +
  geom_col(aes(color = teams, fill = teams), width = 0.5) +
  scale_color_nfl(type = "secondary") +
  scale_fill_nfl(alpha = 0.4) +
  scale_y_nfl() +
  theme_minimal() +
  theme_y_nfl()

Warning messages:
1: Position guide is perpendicular to the intended axis. Did you mean to specify a different guide `position`? 
2: guide_axis(): Discarding guide on merge. Do you have more than one guide with the same position? 
3: guide_axis(): Discarding guide on merge. Do you have more than one guide with the same position? 

Expected behavior
The logos should replace the team abbreviation on the y-axis

Session information
Please copy the output of sessionInfo() into the box below.

R version 4.1.1 (2021-08-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_3.3.5       nflplotR_0.0.0.9004 remotes_2.4.0      

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7        compiler_4.1.1    pillar_1.6.2      prettyunits_1.1.1 tools_4.1.1       digest_0.6.27     pkgbuild_1.2.0   
 [8] lifecycle_1.0.1   tibble_3.1.4      gtable_0.3.0      pkgconfig_2.0.3   rlang_0.4.11      reprex_2.0.1      DBI_1.1.1        
[15] cli_3.0.1         rstudioapi_0.13   curl_4.3.2        xml2_1.3.2        withr_2.4.2       dplyr_1.0.7       generics_0.1.0   
[22] fs_1.5.0          vctrs_0.3.8       gridtext_0.1.4    ggtext_0.1.1      rprojroot_2.0.2   grid_4.1.1        tidyselect_1.1.1 
[29] glue_1.4.2        R6_2.5.1          processx_3.5.2    fansi_0.5.0       farver_2.1.0      callr_3.7.0       purrr_0.3.4      
[36] magrittr_2.0.1    scales_1.1.1      ps_1.6.0          ellipsis_0.3.2    assertthat_0.2.1  colorspace_2.0-2  labeling_0.4.2   
[43] utf8_1.2.2        munsell_0.5.0     crayon_1.4.1  

Screenshots
Rplot

Release nflplotR 1.3.1

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Polish NEWS
  • urlchecker::url_check()
  • devtools::build_readme()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md
  • git push
  • devtools::check_mac_release()
  • rhub::check_for_cran(email = "[email protected]", show_status = FALSE)
  • pkgdown::check_pkgdown()
  • usethis::use_tidy_thanks()

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version(push = TRUE)

Release nflplotR 1.2.0

Prepare for release:

  • Create release branch usethis::pr_init("CRAN-1.2.0")
  • usethis::use_version('minor')
  • Check current CRAN check results
  • Polish NEWS
  • urlchecker::url_check()
  • devtools::build_readme()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran(email = "[email protected]", show_status = FALSE)
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md
  • devtools::check_mac_release()
  • usethis::use_tidy_thanks()
  • pkgdown::check_pkgdown()
  • usethis::pr_push()

Submit to CRAN:

  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • Merge branch CRAN-1.2.0
  • usethis::use_github_release()
  • Tweet

Add a median_geom()

It'd be great to have an automatic way to plot the median/mean for the vertical/horizontal lines. This can be relatively lightweight via {{col}}or you could go further into the grob world to automatically bring in the x/y aes(). I know Ben and others do a lot of logo plots that also include relative mean/medians by axis.

library(ggplot2)
median_geom <- function(x,y, color = "red", linetype = "dashed"){
  list(
    geom_vline(aes(xintercept = median({{x}})), color = color, linetype = linetype),
    geom_hline(aes(yintercept = median({{y}})), color = color, linetype = linetype)
  )
}
ggplot(mtcars) +
  geom_point(aes(x = disp, y = mpg)) +
  median_geom(disp, mpg)

Created on 2021-09-07 by the reprex package (v2.0.0)

Release nflplotR 1.3.0

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Check if any deprecation processes should be advanced, as described in Gradual deprecation
  • Polish NEWS
  • urlchecker::url_check()
  • devtools::build_readme()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md
  • git push
  • Draft blog post
  • devtools::check_mac_release()
  • rhub::check_for_cran(email = "[email protected]", show_status = FALSE)
  • pkgdown::check_pkgdown()
  • usethis::use_tidy_thanks()

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • Add preemptive link to blog post in pkgdown news menu
  • usethis::use_github_release()
  • usethis::use_dev_version(push = TRUE)
  • Finish blog post
  • Tweet

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.