我希望构建一个绘图,基本上与我使用ggplots'stat_bin2d'层生成的绘图相同,但是不是将计数映射到变量,我希望与bin关联的计数显示为每个bin的标签.
我从另一个线程得到了等效的1D问题的以下解决方案
data <- data.frame(x = rnorm(1000), y = rnorm(1000))
ggplot(data, aes(x = x)) +
stat_bin() +
stat_bin(geom="text", aes(label=..count..), vjust=-1.5)
Run Code Online (Sandbox Code Playgroud)
每个垃圾箱的计数都有明确标记.然而,从1D变为2D情况,这是有效的,
ggplot(data, aes(x = x, y = y)) +
stat_bin2d()
Run Code Online (Sandbox Code Playgroud)
但这会返回错误.
ggplot(data, aes(x = x, y = y)) +
stat_bin2d() +
stat_bin2d(geom="text", aes(label=..count..))
Error: geom_text requires the following missing aesthetics: x, y
Run Code Online (Sandbox Code Playgroud)