AdamO
AdamO

Reputation: 4930

matrix of hexbin plots with common bin/legend breaks

Suppose I have a number of replications of bivariate experiments which I wish to display simultaneously in hexagonally binned plots, with common cell counts. Is there existing code to do this? Is there an easy way to modify the hexbin package to do this for me?

For example:

library(hexbin)
x <- replicate(9, rnorm(10000), simplify=FALSE)
y <- replicate(9, rnorm(10000), simplify=FALSE)
h <- mapply(hexbin, x, y)
par(mfrow=c(3,3))
lapply(h, plot)

This code doesn't display a grid of hexbin plots with common cell counts, but I'd like it to.

Upvotes: 1

Views: 597

Answers (1)

dcarlson
dcarlson

Reputation: 11046

hexbin objects are plotted using grid graphics so your par(mfrow=c(3,3)) does not do anything. Each graph is plotted on a separate page. To get the details of the plot options:

?gplot.hexbin

In this case, we want to set maxcnt to the largest cell count:

lapply(h, plot, maxcnt=max(unlist(lapply(h, function(x) max(x@count)))))

This will apply the same legend to each graph.

Upvotes: 2

Related Questions