GGplot2:geom_hex标签

ako*_*ako 2 r ggplot2

我想为geom_hex添加标签,这引发了两个问题:

  1. 我如何得到他们的坐标;
  2. 我如何提取他们的计数值?

最小的例子:

pipeline <- read.csv(url('http://dl.dropboxusercontent.com/u/7446674/pipeline.csv'),sep="\t",header=T)
pipeline <- pipeline[pipeline$Units>0,]

ggplot(pipeline,aes(x=Longitude,y=Latitude))+
    #stat_density2d(n=25,aes(fill=..level..), geom="polygon") +
      geom_hex(bins=12)+
      coord_equal(ratio = 1/1)+
      theme_bw()+
      ggtitle('San Francisco Development Pipeline\nQ2 2013')
Run Code Online (Sandbox Code Playgroud)

(另外,在geom_hex上,如果有人知道称重是否已经实现,我也有兴趣了解它) 在此输入图像描述

Mar*_*ius 5

您可以使用以下方法为每个bin标记其计数:

ggplot(pipeline,aes(x=Longitude,y=Latitude))+
  geom_hex(bins=12)+
  stat_binhex(aes(label=..count..), geom="text", bins=12, colour="white") +
  coord_equal(ratio = 1/1)+
  theme_bw()+
  ggtitle('San Francisco Development Pipeline\nQ2 2013')
Run Code Online (Sandbox Code Playgroud)

(PS:这是你想要的标签吗?看起来那样,但我并不完全确定)

标记计数