stat_density2d bins

Hi,

I was wondering what you guys think is the best number of bins to use in this example. I am making a heat map of swing and misses for a certain baseball player.

ggplot()+
stat_density2d(data=troutswing,aes(x = plate_x, y = plate_z, fill = as.numeric(..level..)),
geom = "polygon",show.legend = FALSE,bins=5) +
geom_point(data=troutswing,aes(x = plate_x, y = plate_z), color="black", size=.95) +
xlab("plate_x")+ylab("plate_z")+xlim(-2,2)+ylim(0,4.5)+scale_fill_gradient2(mid = "yellow",high = "red",
midpoint = 0)+theme_classic()+geom_path(data=xxx, aes(x=xx,y=zz))+geom_path(data=sz,
aes(x=x,y=z))+ coord_equal()+
ggtitle("Whiffs")+ theme(plot.title = element_text(hjust = 0.5))

In these pictures, I have bins set as 5 & 30. I am not sure how to choose the best number.
Thanks!!


whiffsno

I would answer this question by asking myself which features in the plot are worth mentioning. Assuming that the darker color is better, one might say that the first chart shows a preference for pitches towards the left and higher; almost the entire left side of the square is darker than the right side. The chart with more contours shows some detail one would not guess from the first chart such as the very darkest spot is nowhere near the center of the second darkest region and in the lower part of the square there is a definite skew to the left. Are those details interesting or do they distract the viewer from the main message?

1 Like

Yes, darker is better in these plots. I definitely think those details are interesting. That leads me to my next question, why should I not keep increasing the bins? Is there a good way to find out the ideal amount of bins or is it just completely personal preference?

I do not know of any formal way to pick the number of bins. But looking at the plot with 30 bins, I cannot identify anything like 30 different levels. I see 11, though my color perception is not good. If you drop the number of bins, do you see less information?

2 Likes

My fault, the second picture does not have 30 bins. I have posted the wrong picture. Thanks for your help.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.