# How to measure the area of a hexagonal bin generated using ggplot2?

I've generated a number of plots using the `geom_hex` and `stat_summary_hex` functions in `ggplot2`, and I've adjusted the number of bins until the plot "looked right." That said, I'd like to know the area each bin represents to help interpret the plot.

Below is a simplified example of the set of example data and plot:

``````    library(dplyr)
library(ggplot2)
library(rgeos)
library(maptools)
library(rgdal)
library(hexbin)

homicides <- crime %>% dplyr::select(long = ï..X, lat = Y, OFFENSE) %>%
filter(OFFENSE == "HOMICIDE")

coordinates(homicides) <- ~long + lat
homicides.df <- data.frame(homicides)

homicides.hex <- ggplot() +
geom_hex(data = homicides.df, aes(x=long, y =lat),
fun = sum, bins = 20) +
coord_equal()
print(homicides.hex)
``````

Is there a function or method to measure the area (in square miles or kilometers) of an individual hexagon when the x and y axes are latitude and longitude?

• Each row of cells has different area than the row above or below it. – Vince May 27 '17 at 0:42
• @Vince I'm actually interested in measuring the area of a single hexagon that was generated. I edited the question to clarify my need. – Dave May 27 '17 at 4:54
• A polygon is a polygon, no matter how many sides. All you need is a geodetic area function. – Vince May 27 '17 at 11:53

``````> pol <- rbind(c(-120,-20), c(-80,5), c(0, -20), c(-40,-60), c(-120,-20))
• This looks promising, but I'm not sure how to extract all of the points of one of the hexagons in order to input the values into the `geosphere::areaPolygon()` function. Any ideas? – Dave May 30 '17 at 14:50