How can I use stat_bin2d with pre-encoded data?

I want to generate a stat_bin2d() graph, but for the data pre-binned ;

i.e. Instead of starting points

  xy
 5 3
 13 4
 13 14
 16 12 
 15 13

Instead, instead of data previously encoded using corner points, in this case.

  xy freq
 0 0 1
 0 10 0
 10 0 1
 10 10 3

I suppose this may have something to do with the stat_bin2d data parameter, but I cannot find any doco for this.

+4
source share
1 answer

You can use geom_bin2d() (with "identity" status) or just draw rectangles.

 dat <- data.frame(x=c(0,0,10,10), y=c(0,10,0,10), freq=c(1,0,1,3)) ggplot(dat) + geom_bin2d(aes(xmin=x, ymin=y, xmax=x+10, ymax=y+10, fill=freq), stat="identity") ggplot(dat) + geom_rect(aes(xmin=x, ymin=y, xmax=x+10, ymax=y+10, fill=freq)) 
+4
source

All Articles