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.
- 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_gradientnmade this very simple using the limits argument.
- 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.
- Fangraphs is a wonderful resource, but the lack of a nice API is frustrating.
- Shiny is so cool and easy to use.
code to be posted soon