5

Does anyone know if its possible to map to hexagon size with ggplot? Size is listed as an argument in the geom_hex documentation, but there are no examples of size mapping in stat_hexbin, so this just seems to relate to bin size.

Take for example:

ggplot(economics, aes(x=uempmed, y=unemploy)) + geom_hex()

enter image description here

But looking for instance at population distribution (below) it might be useful to map binned mean population to hexagon size, but I've not found a formula for this (if one exists).

ggplot(economics, aes(x=uempmed, y=unemploy, col=pop)) + geom_point()

enter image description here

Any ideas?

geotheory
  • 22,624
  • 29
  • 119
  • 196
  • I doubt that this is implemented. If you think about the algorithm for that, it seems quite complicated to do and would probably require an iterating procedure. – Roland Jun 03 '13 at 10:59
  • @Roland, I'm confused why you think that. If you determine the bin size externally, you can then choose the size of the hexagons independently (although they will have an upperlimit without overlapping). – Andy W Jun 03 '13 at 12:08
  • Well, if you want the size depend on binned mean population, you first have to bin with a fixed size. Then calculate the binned mean population. Than rebin based on this, which could change the binned mean population. Repeat. – Roland Jun 03 '13 at 12:13
  • 2
    The bin tessellation is, as I understand, independent of subsequent stat calculations, in which `geom_hex` assumes a density function of points on xy plane. In principle couldn't ggplot devs tweak the same tessellation to automatically bin population, perhaps with an `aes(size=pop)` addition to geom_hex / stat_binhex? – geotheory Jun 03 '13 at 13:07

1 Answers1

2

Apparently the official answer is that ggplot does not have functionality to map to hexagon area. But as you can see a workaround solution is possible, now posted in a gist at github.

enter image description here

geotheory
  • 22,624
  • 29
  • 119
  • 196