MLB Stats - R Shiny

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: 

About Author

Leave a Comment

No comments found.

View Posts by Categories

Our Recent Popular Posts

View Posts by Tags

#python #trainwithnycdsa 2019 airbnb Alex Baransky alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus API Application artist aws beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep Bundles California Cancer Research capstone Career Career Day citibike clustering Coding Course Demo Course Report D3.js data Data Analyst data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization Deep Learning Demo Day Discount dplyr employer networking feature engineering Finance Financial Data Science Flask gbm Get Hired ggplot2 googleVis Hadoop higgs boson Hiring hiring partner events Hiring Partners Industry Experts Instructor Blog Instructor Interview Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter lasso regression Lead Data Scienctist Lead Data Scientist leaflet linear regression Logistic Regression machine learning Maps matplotlib Medical Research Meet the team meetup Networking neural network Neural networks New Courses nlp NYC NYC Data Science nyc data science academy NYC Open Data NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time Portfolio Development prediction Prework Programming PwC python python machine learning python scrapy python web scraping python webscraping Python Workshop R R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn Selenium sentiment analysis Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau team TensorFlow Testimonial tf-idf Top Data Science Bootcamp twitter visualization web scraping Weekend Course What to expect word cloud word2vec XGBoost yelp