Function Repository Resource:

DorlingCartogram

Source Notebook

Create a non-overlapping cartogram type with visual equalization, partial topology preservation and no shape preservation

Contributed by: Björn Zimmermann

ResourceFunction["DorlingCartogram"][locval]

generates a graphic of non-overlapping circles for initial locations loc with areas corresponding to val.

ResourceFunction["DorlingCartogram"][{loc1val1 ,loc2val2,}]

generates a graphic of non-overlapping circles with initial locations loci with areas corresponding to vali.

ResourceFunction["DorlingCartogram"][spec,n]

generates a graphic of non-overlapping regular n-sided polygons with initial locations and values as given by spec.

Details and Options

ResourceFunction["DorlingCartogram"] returns Graphics.
The locations loc can be coordinate pairs, a GeoPosition, or Entity or EntityClass objects with geographic coordinates, such as cities or countries.
Numerical values associated to locations can be given either explicitly, or, for Entity or EntityClass objects, specified as a Property that evaluates to a number.
Regular polygons and circles are supported shapes.
ResourceFunction["DorlingCartogram"] creates an arrangement wherein the shapes do not overlap, while also moving them minimally from their true (initial) location.
In general, the initial topology is not preserved.
Location value pairs can be given in an Association.

Examples

Basic Examples (4) 

Define an example dataset of random values:

In[1]:=
data = Thread[
   Rule[RandomReal[{0, 100}, {10, 2}], RandomReal[10^6, 10]]];

Create a cartogram with circles:

In[2]:=
ResourceFunction["DorlingCartogram"][data]
Out[2]=

Create a cartogram for the 250 most populous cities in the United States:

In[3]:=
ResourceFunction["DorlingCartogram"][
 EntityValue[
   EntityClass[
    "City", {"Country" -> Entity["Country", "UnitedStates"], "Population" -> TakeLargest[100]}], "Entities"] -> "Population"]
Out[3]=

Create a non-overlapping cartogram for the 250 most populous cities in the United Kingdom:

In[4]:=
ResourceFunction["DorlingCartogram"][
 EntityValue[
   EntityClass[
    "City", {"Country" -> Entity["Country", "UnitedKingdom"], "Population" -> TakeLargest[250]}], "Entities"] -> "Population", ColorFunction -> "Aquamarine"]
Out[4]=

Create a non-overlapping cartogram for the level-2 administrative division in the United Kingdom:

In[5]:=
UKadd1 = EntityList[
   Entity["AdministrativeDivision", {EntityProperty[
       "AdministrativeDivision", "ParentRegion"] -> Entity["Country", "UnitedKingdom"]}]];
In[6]:=
UKadd2 = Flatten[EntityList[
      Entity["AdministrativeDivision", {EntityProperty[
          "AdministrativeDivision", "ParentRegion"] -> #}]] & /@ UKadd1];
In[7]:=
ResourceFunction["DorlingCartogram"][
 Style[UKadd2 -> "Population", Directive[EdgeForm[], FaceForm[Orange]]], "Method" -> "AdjustedStepSize"]
Out[7]=

Options (14) 

ColorFunction (1) 

Create a cartogram for the 250 most populous cities in India:

In[8]:=
ResourceFunction["DorlingCartogram"][
 EntityValue[
   EntityClass[
    "City", {"Country" -> Entity["Country", "India"], "Population" -> TakeLargest[250]}], "Entities"] -> "Population", "Square", ColorFunction -> "Rainbow"]
Out[8]=

ColorFunctionScaling (1) 

Create a cartogram for the 250 most populous cities in Poland:

In[9]:=
ResourceFunction["DorlingCartogram"][
 EntityValue[
   EntityClass[
    "City", {"Country" -> Entity["Country", "Poland"], "Population" -> TakeLargest[250]}], "Entities"] -> "Population", 5, ColorFunction -> Function[{z}, Hue[Log[z]]], ColorFunctionScaling -> False]
Out[9]=

ImageSize (2) 

Define an example dataset:

In[10]:=
data = Thread[
   Rule[RandomReal[{0, 100}, {10, 2}], RandomReal[10^6, 10]]];

The default method "FixedStepSize" employs a step size on the magnitude of scale, which enables a quick calculation of many iterations:

In[11]:=
ResourceFunction["DorlingCartogram"][data, ImageSize -> 100]
Out[11]=

MaxIterations (2) 

The default of the maximum number of potential iterations is coupled to the method. The computation can finish earlier if no shapes overlap anymore.

Define an example dataset:

In[12]:=
data = Thread[
   Rule[RandomReal[{0, 1000}, {100, 2}], RandomReal[10^6, 100]]];

MaxIterations0 returns the initial configuration:

In[13]:=
ResourceFunction["DorlingCartogram"][data, MaxIterations -> 0]
Out[13]=

Method (3) 

Supported methods are "FixedStepSize" and "AdjustedStepSize".

Define an example dataset:

In[14]:=
data = Thread[
   Rule[RandomReal[{0, 1000}, {100, 2}], RandomReal[10^6, 100]]];

The default method "FixedStepSize" employs a step size on the magnitude of scale, which enables a quick calculation of many iterations:

In[15]:=
ResourceFunction["DorlingCartogram"][data, Method -> "FixedStepSize"]
Out[15]=

In the "AdjustedStepSize" method, the step size is adjusted after each step, which leads to good visual results after just a few iterations, but often slows overall convergence:

In[16]:=
ResourceFunction["DorlingCartogram"][data, Method -> "AdjustedStepSize"]
Out[16]=

Rotate (2) 

Define an example dataset:

In[17]:=
data = Thread[
   Rule[RandomReal[{0, 1000}, {100, 2}], RandomReal[10^6, 100]]];

Rotate the regular triangle shape by 30 degrees counterclockwise:

In[18]:=
ResourceFunction["DorlingCartogram"][data, 3, "Rotate" -> (30 Degree)]
Out[18]=

Scale (3) 

Define an example dataset:

In[19]:=
data = Thread[
   Rule[RandomReal[{0, 1000}, {100, 2}], RandomReal[10^6, 100]]];

The default scale is determined such that approximately a quarter of the available space is filled:

In[20]:=
ResourceFunction["DorlingCartogram"][data]
Out[20]=

Use a custom scale:

In[21]:=
ResourceFunction["DorlingCartogram"][data, "Scale" -> 0.02]
Out[21]=

Version History

  • 1.0.0 – 12 August 2020

Source Metadata

Related Resources

License Information