2013-10-01 117 views
2

我想添加标签geom_hex,这产生了两个问题: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') 

(此外,在geom_hex,如果有谁知道,如果晕死一直没有实现我会有兴趣知道,太) enter image description here

回答

5

你可以使用以下标记来标记每个垃圾箱:

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') 

(PS:是你想要的数量吗? abels?似乎这样,但我不能完全肯定)

Labelled counts

+0

的作品就像一个魅力! – ako

+0

计数很好,除非我可以用stat_binhex来衡量观察结果,但我认为这还没有实现。 – ako