一部の NBA プレーヤーとチームのシュート傾向/有効性を表示するために、いくつかのチャートを作成したいと考えています。六角形を次のようにフォーマットしたいと思います。サイズはショットの数を表し、色はその場所からの相対的な効率 (ポイント/試行) を表します。Kirk Goldsberry によって作成された、私が探しているものの良い例を次に示します。
hexbins
and を使用しhexTapply
て、目的の結果に近いものを達成することができましたが、形状は円です。これが私のコードです(サンプルデータが含まれています):
library(hexbin); library(ggplot2)
df <- read.table(text="xCoord yCoord pts
11.4 14.9 2
2.6 1.1 0
4.8 4.1 2
-14.4 8.2 2
4.2 0.3 0
0.4 0.0 2
-23.2 -1.1 3", header=TRUE)
h <- hexbin (x=df$xCoord, y = df$yCoord, IDs = TRUE, xbins=50)
pts.binned <- hexTapply (h, df$pts, FUN=mean)
df.binned <- data.frame (xCoord = h@xcm,
yCoord = h@ycm, FGA = h@count, pts = pts.binned)
chart.player <- ggplot (df.binned, aes (x =xCoord ,
y =yCoord , col = pts, size = FGA)) + coord_fixed() +
geom_point() + scale_colour_gradient("Points/Attempt", low = "green", high="red")
それについて考える別の方法はplot(h, style="lattice")
、ポイント/試行で六角形を色付けすることです-しかし、それを行う方法もわかりません。
円ではなく六角形でこのグラフを取得する方法はありますか?