开发者

How do I change how data is binned for geom_hex()?

Could someone point me to an example of how to use something other than ..count.. for the fill? I have a data set with over 100k observations of two variables on [0,1] and a set of weights. I want to make a scatterplot that shows the structure of the data without relying on a sample. Right now I am using alpha for the overplotting and size for the weights like this:

ggplot( data= cropScatDf, aes( agland, nomos1, size= weight)) +
  geom_point( alpha= 0.03) +
  scale_area( limits= c(0.7, 1),
             breaks= seq( 0.7, by= 0.1),
             to= c(0.7, 1) *6) 

And it works okay, but the visual quality varies depeding on my ggsave() settings. So now I have this:

开发者_如何学Go
ggplot( data=cropScatDf, aes( agland, nomos1)) + 
   stat_binhex( binwidth=c(0.05, 0.05)) + 
   scale_fill_gradientn( colours= brewer.pal( 6, "YlGn"), 
                        trans= "log10", 
                        limits=c(100,50000))

and this does a pretty good job of showing the structure but I want to be able to say that I have applied the weights to the bins rather than just accepting a straight count. Is this possible? I imagine there is some subtlety of the grammar that I am not grasping. Is there a way that I can cook my data before bringing it to ggplot() to get the desired effect? Can I write my own transformer?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜