Pitch Location Charts with PITCHf/x and ggplot

Visually analyze each at-bat of a baseball game.
4.9 (22 ratings) Instead of using a simple lifetime average, Udemy calculates a
course's star rating by considering a number of different factors
such as the number of ratings, the age of ratings, and the
likelihood of fraudulent ratings.
2,462 students enrolled
Free
Start Learning Now
  • Lectures 37
  • Length 2 hours
  • Skill Level Intermediate Level
  • Languages English
  • Includes Lifetime access
    30 day money back guarantee!
    Available on iOS and Android
    Certificate of Completion
Wishlisted Wishlist

How taking a course works

Discover

Find online courses made by experts from around the world.

Learn

Take your courses with you and learn anywhere, anytime.

Master

Learn and practice real-world skills and achieve your goals.

About This Course

Published 7/2015 English

Course Description

In this course, we make use of PITCHf/x data to create pitch location charts for a given baseball game. We break the game out into each at-bat and visualize the location, type, and speed of each pitch, the order in which the pitches were thrown, and the outcome of the at-bat.

In order to accomplish this, we will be taking a deep dive into ggplot. We will learn much about how to work with color, how to use aesthetics, and how to facet. We will also gain additional R skills, such as how to subset a vector and how to work with factors.

One should be able to complete the course, at a relaxed pace, in about three weeks. It is best if students already have a little bit of a background in R, dplyr, and ggplot, but it is not completely necessary.

What are the requirements?

  • Students will need to have R and RStudio installed on their own computers.

What am I going to get from this course?

  • scrape PITCHf/x data into an R session
  • plot pitch locations with ggplot
  • visualize pitch type and speed with ggplot
  • subset vectors in R
  • work with color in ggplot
  • facet in ggplot
  • label with geom_text
  • work with seq, lapply, unlist, and unique in R
  • save plots as png's
  • write for loops in R
  • work with factors in R

What is the target audience?

  • This course is for students interested in learning how to create pitch location charts and how to wrangle data from PITCHf/x.
  • It would be best for each student to have a bit of a background in R, dplyr, and ggplot, but it is not completely necessary.

What you get with this course?

Not for you? No problem.
30 day money back guarantee.

Forever yours.
Lifetime access.

Learn on the go.
Desktop, iOS and Android.

Get rewarded.
Certificate of completion.

Curriculum

Section 1: Extracting PITCHf/x Data
01:01

In this video, I state the goals of the course.

04:14

After viewing this lecture, you will know where to access PITCHf/x data and understand a bit about its structure.

04:50

After viewing this lecture, you will be able to scrape the data for a single game from the PITCHf/x website and access the data frames in which the data is stored.

04:46

After viewing this lecture, you will be able to join the atbat and pitch data frames.

04:39

In this lecture, we select what we need from the atbat data frame.

02:31

In this lecture, we select what we need from the pitch data frame.

Section 2: Multi-Batter Visualizations
01:50

In this lecture, I give the coordinates of the strike-zone.

04:24

After viewing this lecture, you will be able to work with geom_path to draw a strike-zone with ggplot.

02:26

After viewing this lecture, you will be able to plot all of the pitches thrown by Max Scherzer as points.

03:42

After viewing this lecture, you will be able to use the ggplot size parameter within the aesthetics to visualize the speed of each pitch.

03:17

After viewing this lecture, you will be able to use the ggplot color parameter within the aesthetics to visualize the type of each pitch.

04:27

After viewing this lecture, you will be able to subset vectors and use the "which" function in R.

04:37

After viewing this lecture, you will be able to use the "which" function to generate a more descriptive pitch type column.

Section 3: Working with Color
03:59

After viewing this lecture, you will be able to set the hue of points in ggplot.

01:49

After viewing this lecture, you will be able to set the chromaticity, or saturation, of points in ggplot.

01:08

After viewing this lecture, you will be able to set the luminance, or brightness, of points in ggplot.

01:51

After viewing this lecture, you will be able to use the RColorBrewer package to pick a color palette for displaying points in ggplot.

03:04

After viewing this lecture, you will be able to manually specify your own color palette for displaying points in ggplot.

05:02

After viewing this lecture, you will understand factors and you will be able to work with them.

Section 4: Faceting
05:06

After viewing this lecture, you will be able to facet in ggplot, and you will also be able to work with geom_text.

04:10

In this lecture, we do more problem solving with the "which" function.

01:32

In this lecture, we do more problem solving with factors.

05:34

In this lecture, we do more problem solving with faceting and geom_text.

Section 5: At-Bat by At-Bat
05:41

In this lecture, we separate out a single at-bat for visualization. We also learn how to work with the paste function and how to set limits for the axes.

04:30

In this lecture, we do more problem solving with geom_text, and we learn about the vjust parameter.

05:27

In this lecture, we do more problem solving with the "which" function.

03:47

In this lecture, we review grouping and counting with dplyr.

02:01

After viewing this lecture, you will be able to use the seq and lapply functions in R.

01:49

After viewing this lecture, you will be able to work with the unlist function.

02:23

In this lecture, we finally enumerate the pitches within each at-bat.

Section 6: Slide-Show
02:36

After viewing this lecture, you will be able to save a plot from ggplot to a png.

03:38

In this lecture, we learn how to write a for loop. We also learn how to work with the unique function.

03:41

In this lecture, we make the necessary changes to our code withing the for loop.

02:41

In this lecture, we discover two additional problems we must solve before our final product is satisfactory.

04:12

In this lecture, we learn how to work with the names function to solve our color problem.

04:59

In this lecture, I discuss the mappings of intervals to intervals, a technique that will help us solve our speed problem.

03:58

In this lecture, we implement the solution described in the last lecture and wrap-up the course.

Students Who Viewed This Course Also Viewed

  • Loading
  • Loading
  • Loading

Instructor Biography

Charles Redmond, Professor at Mercyhurst University

Dr. Charles Redmond is a professor in the Tom Ridge School of Intelligence Studies and Information Science at Mercyhurst University. He has been a member of the Department of Mathematics and Computer Systems at Mercyhurst for 21 years and has recently completed a term as chair of the department. Dr. Redmond received his PhD in mathematics from Lehigh University in 1993 and has published in the Annals of Applied Probability, the Journal of Stochastic Processes and Their Applications, Mathematics Magazine, the College Mathematics Journal, and Mathematics Teacher. In his spare time he enjoys making music and computer generated art, reading, and owning a Clumber Spaniel.

Ready to start learning?
Start Learning Now