# How to create contiguous area cartograms in QGIS or R?

Here is what I want to achieve (on the right):

I am looking for a tool or a method to transform a shapefile (with QGIS or R) into this form. And please be aware: It's not just clipping a hexagonal grid or a grid of hexagons! Each hexagon should represent an equal number of a measure (e.g. each hexagon represents 5,000 trees).

Maybe you know about scapetoad! http://scapetoad.choros.ch/ So I basically want to produce a similar output to scapetoad - but with a more restricted grid(?).

edit: The mentioning of QGis and R is not a restriction - it's just where I was looking for a solution. Of course I am happy with any tool, method or advise!

-
The title on the image you reference names it for you (at least generically); so does the title of that scapetoad page: it is a "cartogram." More specifically, it is a (contiguous) area cartogram that employs hexagonal elements. – whuber Mar 9 '13 at 22:01

Meanwhile I'll present what's my idea so far:

1. Produce a cartogram on a 'diffusion-based' method (like scapetoad).

In QGis:

2. Create a point-layer [Vector > Research Tools > Regular Points].

3. Clip point-layer with cartogram.

4. Create a hexagonal-layer [Plugins > Qmarxan > Create Planning Grid] (use appropriate/ desired number of hexagons).

5. Count points per polygon [Vector > Analysis Tools > Points in Polygon].

6. In the layer properties of the hexagonal-layer: Apply rule-based labelling (or clipping) [Filter: "PKTCNT" >= 1].

That's all I have so far.

Shortcomings are:

a) This is just the overall shape (subunits have to be worked out again...)

b) The number of Hexagons is somewhat arbitrary linked to the actual measure, and worse

c) if I want to change the unit of the measure (e.g. instead of 5'000 trees per hexagon, now I want 100'000 trees per hexagon = further reducing complexity/detail) I have to do the whole procedure again.

-

A slightly more satisfying procedure:

1. Produce a cartogram on a 'diffusion-based' method (like scapetoad).

In QGis:

2. Create a hexagonal-layer [Plugins > Qmarxan > Create Planning Grid] (use appropriate/ desired number of hexagons). edit: Depending on the purpose of the map, Qmarxans grid could be of dubious quality. The mmqgis plugin produces much better results (polygons align perfectly).

3. Join the the hexagonal-layer with the cartogram [Vector > Data Managment Tools > Join attributes by location]

4. Now the new hexagonal-layer has all the properties/attributes from the cartogram, and it is possible to access each subunit individually.

5. For better shape-preservance of subunits some manual tweeking is possible: Select the hexagon(s) and change the attribute(s) directly in the attribute-table. This step works best, if the layer is semi-transparent and the original diffusion-based cartogram is shown below.

6. Merging the hexagons of a subunit to one unit: 1. Select all hexagons of a subunit (if many: use attribute-table for selection). 2. 'toggle edit' > 'merge selected features'.

Mainly shortcoming b) remains - but a) is solved and also to some degree c) isn't a big problem anymore, b/c this method doesn't take that much time.

Edit: Step 4. (and colored afterwards) leads to this result (transparent hexagon-layer on top, 'diffusion-based' cartogram below):

The bright-green hexagons clearly take one row to much...

Any ideas how it is possible to achieve a better/ a custom fitting of the "join attributes"? - I am looking for a method to give the algorithm some kind of threshold (like: >50% of area).

-
I can vouch for this approach, I've done it successfully. Not worked out a satisfactory way to spatially join the hexes to the polygon which has the greatest overlap; I suspect that would need postgresql/postgis (Join attributes by location just matches the first one it finds, which may not be optimal) – Steven Kay Apr 8 at 19:12