Create your own hexamaps

hexdk

Hexamaps are gaining in popularity. Most notably has been the versions, where the map of the USA has been made into a hexamap. But people have also made maps of Europe using hexagons.

The idea is that one unit is one hexagon. So in case of the US, each state is one hexagon. In the case of Europe, each country is a hexagon.

This means that all units (states, countries, etc.) are the same size. This of course skews the hexamap in relation to the real geographic proportions. But it gives the advantage of giving all units equal size for displaying information – for instance a shade or color depending on some underlying values.

I have made a hexamap of the municipalities in Denmark. The capital region is very dense so I had to sort of map that on the side. You can see my efforts here:

hexdk

To ease the process I’ve made the hexamapmaker package. It takes a set of points and turns them into hexagons. That means that you can quickly and easily design and produce hexamaps.

Below I’ve included the example code from the package if you want to get started yourself. If you create a map of your own please share it with me on twitter @mikkelkrogsholm. I’d love to see your work!
# Install hexamapmaker
devtools::install_github(“56north/hexamapmaker”)
library(hexamapmaker)

# Create data frame
# Notice the spacing of the points

x <- c(1,3,2,4,1,3,7,8)
y <- c(1,1,3,3,5,5,1,3)
id <- c(“test1”, “test2”, “test3”, “test4”, “test5”, “test6”, “test7”, “test8″)
z <- data.frame(id,x,y)

# Plot points

library(ggplot2)
ggplot(z, aes(x, y, group = id)) +
geom_point() +
coord_fixed(ratio = 1) +
ylim(0,max(y)) + xlim(0,max(x))

# Turn points into hexagons

library(hexamapmaker)

zz <- hexamap(z)

ggplot(zz, aes(x, y, group = id)) +
geom_polygon(colour=”black”, fill = NA) +
coord_fixed(ratio = 1)

Showing 9 comments

  1. Jonathan Carroll
    Svar

    “Note: the x’s and y’s must be spaced with 2 apart.”

    Does this mean the central locations need to be manually computed? Did you design the layout for your municipalities map?

    • Mikkel
      Svar

      Yes. You need to compute them manually first. You can use a checkered paper for that. Once your design is done, you give the points to hexamapmaker and it turns them into hexagons. Thats how I designed my municipality map.

  2. Charles O'Riley
    Svar

    Thanks for the exercise. One question I have concerns an error I received when using double quotes instead of a single quote as you did in your example. Using a single quote works fine. The error message was as follows:
    Error: unexpected input in:
    “ggplot(zz, aes(x, y, group = id)) +
    geom_polygon(colour=””

    • Mikkel
      Svar

      Hi Charles. It looks like the ” are different from eachother in the above code snippet.

  3. Scott Davis
    Svar

    Hey, this is awesome. Quick question – what is the right parameter to label the hexagons?

    • Mikkel
      Svar

      Hi Scott. Use the mean of the x’s and y’s per hexagon to get a single point. Then you have the centre of each one. Label that centre how you like. Make sense?

      • Mikkel
        Svar

        I created a new function “hexalabel” to label the polygons. Re-install the package and labelling shoul be a breeze.

  4. Nick
    Svar

    I have a bunch of lattitude and longitude crime data – not equally spaced but roughly a grid corresponding roughly to city blocks. Each point is the center of a block. Can I plot that using hexagons?

    • Mikkel
      Svar

      Hi Nick. If you can get the lat’s and lon’s to fit the “pattern” needed for hexamapmaker then sure.
      I haven’t written any code for that thoug, so you’ll have to figure it out.

Leave a Comment

Din e-mailadresse vil ikke blive offentliggjort. Krævede felter er markeret med *

*