MLB Stats - R Shiny

Avatar
Posted on Aug 11, 2019

The dataset that I chose for this project was a game log of almost every game in MLB history, since 1910. Baseball has become the most analytical professional sport.  The extent of analytics in baseball has gone so far that some teams even use analytics to tell a player whether or not he should swing at a particular pitch.  While this particular set of data doesn’t give any pitch-by-pitch stats, it just goes to show how easily this game can be broken down into numbers, with each pitch being the base case for all other statistics involved. 

One of the challenges of this project was organizing the game log data in a way that would be meaningful, in regards to the league as a whole as well as for individual players.  With over 100 years, over 35 different teams, and the stats of each game being organized by home team and away team, this made deriving some of the stats challenging. 

For this particular project, I decided to visualize a couple parts of the game that have been discussed among commentators and baseball broadcasters over the last few years.  The first part of the game that I’m referring to is the rise of dominant pitching.  A lot of this talk began in 2014 and 2015 when there were clusters of games where pitchers didn’t give up any hits (also known as a no-hitter).  There was also a noticeable increase in the size of the contracts for pitchers, which stirred the conversation as well.  Given game logs that dated back to 1910, I wanted to visualize pitching stats in a way that portrays the evolution of the game.  So, the first graph shown is the average number of strikeouts per game, for one team.  Meaning, if you doubled these numbers, you would get the average total number of strikeouts in a game, but I found the smaller number to be more intuitive for people who know baseball. 

The second graph I did was for season totals of no hitters.  I chose to look at these numbers as part of the rise of dominant pitching.  As you can see, there were a few recent years with a high total number of no hitters but overall, no hitters are too rare for there to be a noticeable steady increase as there is for strikeouts.

Of course, when it comes to looking at sports statistics, one of the common modes of visualization is through a player index.  The set of data I was working with did not give any particular individual player statistics but I was able to derive the number of wins for particular pitchers.  I would have loved to be able to recreate a classic player index with all of their stats but unfortunately the game log did not support it. 

The final part of the project was to look at how the rise of pitching has affected the hitting aspect of the game.  If you know the game of baseball, you understand that each time a batter strikes out, the runners on base are unable to advance.  A common ground ball out still leaves the possibility of a runner advancing and getting closer to scoring a run.  On the other hand, a homerun will score a run no matter what.  So, I decided to take a look and see if there is a correlation between the strikeouts and the ratio of homeruns per runs scored, which is the final visualization.  I also derived the league average for this statistic so teams could be compared to the league average. 

To view the app: https://jdsipala.shinyapps.io/shinyProj/ 

About Author

Leave a Comment

Your email address will not be published. Required fields are marked *

No comments found.

View Posts by Categories


Our Recent Popular Posts


View Posts by Tags