【发布时间】:2018-04-13 19:59:55
【问题描述】:
我正在尝试在篮球场的图像上绘制投篮密度;但是,我无法弄清楚如何制作它,因此忽略密度 = 0 的点。
我目前收到以下信息:
我使用的代码如下:
## LIBRARIES
library(grid)
library(jpeg)
library(RCurl)
library(ggplot2)
library(gridExtra)
library(viridis)
courtImg.URL = "https://thedatagame.files.wordpress.com/2016/03/nba_court.jpg"
court = rasterGrob(readJPEG(getURLContent(courtImg.URL)),
width=unit(1,"npc"), height=unit(1,"npc"))
ggplot(df, aes(x = df$Baseline, y=df$Side)) +
ylim(0, 100) +
ylab(" ") +
xlim(-50, 50) +
xlab("Baseline") +
annotation_custom(court, -50, 50, 0, 100) +
coord_fixed() +
scale_fill_viridis(option='inferno', end=1) +
stat_density_2d(aes(fill =..density..), geom = "raster", contour=FALSE) +
guides(fill = guide_colorbar(title = "% of Shots Taken"))
我想要的输出如下所示:
归根结底,我只是想制作一个热图版本的镜头图。如果有人对我如何能够以完全不同的方式做到这一点有任何建议,我绝对愿意接受!
提前致谢!
【问题讨论】:
标签: r ggplot2 kernel-density density-plot