Getting Started

Welcome to sportyR! I’m Ross Drucker, the author of the sportyR package. My aim with this package is to provide high-quality, reliable, baseline plots to use for geospatial analysis of sports data. I’m excited to showcase some of the main functionalities of the package here, as well as continue to develop the package to meet the needs of the sports analytics community.

Installing R, RStudio, and sportyR

(This section courtesy of Saiem Gilani. Give him a follow!)

  1. Head to
  2. Select the appropriate link for your operating system (Windows, Mac OS X, or Linux)
  1. Head to
  2. Follow the associated download and installation instructions for RStudio.
  3. Start peering over the RStudio IDE Cheatsheet. An IDE is an integrated development environment.
  4. For Windows users: I recommend you install Rtools. This is not an R package! It is “a collection of resources for building packages for R under Microsoft Windows, or for building R itself”. Go to and follow the directions for installation.

sportyR is live on CRAN, and the most recent release can be installed by running:

# Install released version from CRAN

If you’re more into the development version of the package, try this:

# Install development version from GitHub

Once the library is installed, be sure to load it into the working environment.

# Required to use package

Understanding and Exploring the Package

The package itself is really an extension of ggplot2, but the aim is to focus specifically on a sports playing surface. So that begs the question: what sports can we plot using sportyR?

You’re in luck: these kinds of questions are natively answered by what I’ve called the cani_{question}() family of functions. They’re designed to answer questions like

Can I plot a soccer pitch?


Can I plot a PHF ice rink?

and that’s the exact syntax you can follow to have the package answer those questions. Here’s an example:

# Find out if you can plot a soccer pitch
#> geom_soccer() can be used to plot for the following leagues: EPL, FIFA, MLS, NCAA, NWSL


# See if a league comes pre-packaged with sportyR
#> A plot for PHF can be created via the geom_hockey() function

I’ll highlight the fact that these are case-insensitive searches. Ask away to your heart’s content!

There’s one other cani_{question}() function I’ll highlight more in a bit, but first let’s start acting on the answers to these kinds of questions.

The geom_{sport}() Functions

Now that we can ask questions to the package and get answers, let’s start using this information to make plots. Say for example we’re interested in drawing a regulation NBA basketball court. sportyR seeks to make this as easy as possible:

# Draw a regulation NBA basketball court

Easy as that to get started. Here’s a quick overview of the arguments (which are included for all of the geom_{sport}() functions):

Follow the sportsdataverse on Twitter and Star This Repo

Twitter Follow

Twitter Follow

GitHub stars