Earlier this week, I was trying to think of a nice graphic to plot baseball teams statistics in one graphic. A heatmap was an obvious choice and I thought about trying to shape it into a diamond. Below is my attempt at a shiny app where you can select a team and a statistic to view the whole team. Each position is taken as a weighted mean of players that have had at least 120 plate appearances in 2017. The value in the heatmap is the percentile of that positions numbers compared to the rest of the league. Data is from Fangraphs.

Take aways:

  1. I wanted to have a heatmap where the values in the heatmap were relative to values outside the data to create the heatmap (i.e. players values are relative to the league and not their team). The scale_fill_gradientn made this very simple using the limits argument.
  2. Polygons are tricky to draw in R and ggplot2, but after some tweaking I think I was able to get it into a nice format.
  3. Fangraphs is a wonderful resource, but the lack of a nice API is frustrating.
  4. Shiny is so cool and easy to use.





References:

code to be posted soon