Function Repository Resource:

RectangleAreaChart

Source Notebook

Visualize numeric data using tessellated rectangles with proportionate area

Contributed by: Jon McLoone

ResourceFunction["RectangleAreaChart"][{d1,d2,}]

generates a graphic of tessellated rectangles each sized in proportion di.

ResourceFunction["RectangleAreaChart"][{lab1d1,lab2d2,}]

generates a graphic of tessellated rectangles each sized in proportion di labeled with labi.

ResourceFunction["RectangleAreaChart"][assoc]

generates a graphic of tessellated rectangles labeled with the keys of Association assoc.

Details and Options

ResourceFunction["RectangleAreaChart"] is filled from the top left corner to the bottom right corner, attempting to give each rectangle an AspectRatio as close to 1 as possible.
ResourceFunction["RectangleAreaChart"] accepts all options of Graphics, with the following additions:
BoundaryStyleBlackstyle used for edges of the individual rectangles
"ChartColors"Whitethe colors of individual rectangles
"LabelColors"Automaticthe colors of individual labels
"Sorting"Truewhether to sort the data to place the largest values first

Examples

Basic Examples (2) 

Create a chart of three rectangles with relative areas of 3, 2 and 1:

In[1]:=
ResourceFunction["RectangleAreaChart"][{3, 2, 1}]
Out[1]=

Create a chart of three labeled rectangles with relative areas of 3, 2 and 1:

In[2]:=
ResourceFunction["RectangleAreaChart"][{"a" -> 4, "b" -> 2, "c" -> 1}]
Out[2]=

Scope (1) 

Use an association:

In[3]:=
ResourceFunction[
 "RectangleAreaChart"][<|"a" -> 4, "b" -> 2, "c" -> 1, "d" -> 3|>]
Out[3]=

Options (7) 

AspectRatio (1) 

The layout in RectangleAreaChart is influenced by AspectRatio:

In[4]:=
ResourceFunction[
 "RectangleAreaChart"][{"a" -> 4, "b" -> 3, "c" -> 1, "d" -> 1}, AspectRatio -> 0.7]
Out[4]=
In[5]:=
ResourceFunction[
 "RectangleAreaChart"][{"a" -> 4, "b" -> 3, "c" -> 1, "d" -> 1}, AspectRatio -> 1.5]
Out[5]=

BoundaryStyle (2) 

The edges of the rectangles can be styled with BoundaryStyle:

In[6]:=
ResourceFunction["RectangleAreaChart"][{"a" -> 4, "b" -> 2, "c" -> 1},
  "ChartColors" -> {Yellow, White, Pink}, BoundaryStyle -> Dashed]
Out[6]=

Use BoundaryStyleNone to hide the boundaries:

In[7]:=
ResourceFunction["RectangleAreaChart"][{"a" -> 4, "b" -> 2, "c" -> 1},
  "ChartColors" -> {Yellow, White, Pink}, BoundaryStyle -> None]
Out[7]=

ChartColors (2) 

The individual elements can be colored with "ChartColors" using a list of colors. Labels default to black or white depending on the rectangle background color:

In[8]:=
ResourceFunction["RectangleAreaChart"][{"a" -> 4, "b" -> 2, "c" -> 1},
  "ChartColors" -> {Red, Green, Blue}]
Out[8]=

Use a ColorDataFunction capable of taking index values:

In[9]:=
ResourceFunction["RectangleAreaChart"][{"a" -> 4, "b" -> 2, "c" -> 1},
  "ChartColors" -> ColorData[1]]
Out[9]=

LabelColors (1) 

Individual labels can be colored with "LabelColors":

In[10]:=
ResourceFunction["RectangleAreaChart"][{"a" -> 4, "b" -> 2, "c" -> 1},
  "LabelColors" -> {Red, Green, Blue}, BaseStyle -> 20]
Out[10]=

Sorting (1) 

The chart is filled from the top left corner towards the bottom right. For the most even appearance, data is sorted first, but with "Sorting"False, data will be used in the order given:

In[11]:=
ResourceFunction["RectangleAreaChart"][{"b" -> 2, "c" -> 1, "a" -> 4},
  "Sorting" -> False]
Out[11]=

Applications (1) 

Visualize the relative populations of South American countries:

In[12]:=
ResourceFunction["RectangleAreaChart"][
 If[#["Population"] < Quantity[1000000, "People"], None, #["Name"]] -> #["Population"] & /@ EntityList[EntityClass["Country", "SouthAmerica"]], "ChartColors" -> ColorData[10]]
Out[12]=

Publisher

Jon McLoone

Version History

  • 1.0.0 – 13 July 2021

Related Resources

License Information