Search topics and sections

A mosaic plot is a chart that shows how often each combination of categories turns up in a data set. It works with categorical variables, which sort cases into named groups instead of measuring them on a number scale. Statisticians use it to see whether two or more such variables are linked.[1]

The plot starts with one rectangle and cuts it into tiles. Each tile's area is in proportion to the number of cases in one combination, such as people with blond hair and blue eyes.[1] In business the same layout is called a Marimekko chart or Mekko chart, and it is often used to show market share.[2][3]

Reading a mosaic plot

A mosaic plot draws a contingency table, which is a table of counts for every combination of categories. A standard example is a survey by Snee (1974) of 592 students in a statistics course, sorted by hair color and eye color.[4][1]

Eye color Black hair Brown hair Red hair Blond hair Total
Brown 68 119 26 7 220
Blue 20 84 17 94 215
Hazel 15 54 14 10 93
Green 5 29 14 16 64
Total 108 286 71 127 592

The plot turns this table into tiles using three rules.[1]

  • The width of each column shows the share of all students who have that hair color.
  • The height of each tile within a column shows the share of that hair group who have each eye color.
  • The area of each tile (width times height) shows that cell's share of all 592 students.

For example, 286 of the 592 students (about 48 percent) have brown hair, so the brown-hair column is the widest. Within the blond column, 94 of 127 students (about 74 percent) have blue eyes, so the blue tile fills most of that column.[4]

Mosaic plot of hair and eye colorHair colorBlackBrownRedBlondEye colorBrownHazelGreenBluePearson residualAbove 42 to 4-2 to 2-4 to -2Below -4
Mosaic plot of hair and eye color for 592 students (Snee, 1974), with tile area in proportion to the count. Tiles are shaded by Pearson residual (observed minus expected count, divided by the square root of the expected count): blue for dij>2d_{ij} > 2, red for dij<−2d_{ij} < -2, and darker for residuals above 44 or below −4-4.

How a mosaic plot is built

A mosaic plot is built by splitting a square again and again, one variable at a time.[1][4]

  1. Start with a square that stands for all the cases.
  2. Split it into vertical bars, one per category of the first variable. Each bar's width is in proportion to that category's total.
  3. Split each bar into tiles, one per category of the second variable. Each tile's height is in proportion to that category's share within the bar.
  4. To add more variables, split each tile again, switching between vertical and horizontal cuts.

Small gaps between the bars and tiles are common but not required. When the gaps are left out, the chart is sometimes called a Mondrian diagram.[5]

A cell with a count of zero gets a tile of zero area. The R package vcd marks such cells with a small dot so they are not confused with very small tiles.[6]

Building a mosaic plot of hair and eye colorStep 1: one squarefor all 592 studentsStep 2: split byhair colorStep 3: split each barby eye colorBlackBrownRedBlondBlackBrownRedBlondEye colorBrownHazelGreenBlue
A mosaic plot of hair and eye color for 592 students is built in three steps. The square is split into bars whose widths give the share of each hair color, and each bar is then split into tiles whose heights give the share of each eye color within that hair color.

Aligned tiles mean independence

Two variables are independent when knowing one tells you nothing about the other. If hair color and eye color were independent, each eye color would take up the same share of every hair column, so the tile edges would line up straight across the plot.[1] In the student data the edges do not line up, which shows that hair color and eye color are linked.[1]

The counts expected under independence are products of the row and column totals.[7] For the cell in row ii (an eye color) and column jj (a hair color):

mij=ni+ n+jnm_{ij} = \frac{n_{i+}\, n_{+j}}{n}
  • mijm_{ij} is the expected count in that cell.
  • ni+n_{i+} is the total of row ii, and n+jn_{+j} is the total of column jj.
  • nn is the total number of cases.

This formula explains why the tiles align. A tile's height within column jj is nij/n+jn_{ij}/n_{+j}, and if every count equals its expected count, that height is ni+/nn_{i+}/n in every column. This is the share of eye color ii in the whole sample, so it does not depend on the column.

Mosaic plots of hair and eye color: expected under independence and observedIf independent (expected counts)Observed countsBrownHazelGreenBlueBrownHazelGreenBlueBlackBrownRedBlondBlackBrownRedBlond
If hair and eye color were independent, every hair color column would split at the eye color shares of the whole sample (brown eyes 220/592≈0.37220/592 \approx 0.37), so the tile edges line up across columns. In the observed counts the edges are staggered, which shows that eye color is linked to hair color.

Shading by residuals

Michael Friendly added two features in 1994 that make patterns easier to see.[1]

  • Each tile is colored by its residual (the gap between the observed count and the count a chosen model expects), with one color for positive and another for negative values, and stronger color for larger gaps.
  • The categories are put in a new order so that cells with similar residuals sit near each other.

The residual most often used is the Pearson residual:[4]

dij=nij−mijmijd_{ij} = \frac{n_{ij} - m_{ij}}{\sqrt{m_{ij}}}

Here nijn_{ij} is the observed count and mijm_{ij} is the expected count. The sum of the squared residuals is the statistic of Pearson's chi-squared test, which is 138.3 with 9 degrees of freedom for the hair and eye data, a large difference from independence.[4]

By default, a tile is shaded when the absolute value of its residual (its size, ignoring the plus or minus sign) is more than 2 or 4. Because these residuals roughly follow a standard normal distribution, the two levels mark cells that are each significant (unlikely to arise by chance if the variables were independent) at about the 0.05 and 0.0001 levels.[4]

The color shows the sign of the residual. Positive residuals are blue (more cases than independence predicts) and negative residuals are red (fewer cases).[4]

As a worked example, the expected count for blond hair with blue eyes is 127×215/592≈46.1127 \times 215 / 592 \approx 46.1. The observed count is 94, so the residual is (94−46.1)/46.1≈7.05(94 - 46.1)/\sqrt{46.1} \approx 7.05. The table lists the largest residuals in the data.[4]

Hair Eyes Pearson residual Shading
Blond Blue 7.05 dark blue
Black Brown 4.40 dark blue
Red Green 2.28 light blue
Blond Hazel -2.23 light red
Black Blue -3.07 light red
Blond Brown -5.85 dark red

Once the eye colors are reordered as brown, hazel, green, blue, the blue tiles fall on one diagonal and the red tiles on the other. The plot then shows that dark hair goes with dark eyes and light hair with light eyes, while red hair does not quite fit this pattern.[4]

More than two variables

Repeated splitting

Each new variable splits every existing tile into smaller tiles by its share within that tile. For a three-way table with counts nijkn_{ijk}, the cuts are:[7]

  • first variable: widths in proportion to ni++n_{i++},
  • second variable: heights in proportion to nij+/ni++n_{ij+}/n_{i++},
  • third variable: widths in proportion to nijk/nij+n_{ijk}/n_{ij+}.

At every stage the area of a tile is in proportion to its cell count.[1]

In 1984 John Hartigan and Beat Kleiner drew a six-way table of television ratings with larger gaps between categories split earlier. Friendly describes this as an important step, because readers can then tell large groups of tiles from small ones.[1]

Three-way mosaic plot splittingC1C2C1C2C1C2C1C2A1A2B1B21st split: A2nd split: B3rd split: Csimplified
Simplified three-way mosaic plot built from three splits that alternate direction: a vertical split by AA, a horizontal split by BB inside each AA column, and a vertical split by CC inside each tile. Each later split leaves a smaller gap, so the order of the splits stays visible.

Order of variables

The order in which variables are split changes the picture. Mosaic plots are conditional plots by design, meaning they compare variables within groups set by another variable.[6] So a variable that others should be compared within (a conditioning variable) should be split first.[6] Each tile then shows the later variables within one group of the earlier ones.

Fitting models

With three or more variables, the shading can show residuals from different log-linear models of independence. For three variables A, B, and C there are three types.[4]

Model Log-linear notation What the residuals show
Mutual independence [A] [B] [C] All links among the variables
Joint independence [AB] [C] Links between C and the combinations of A and B
Conditional independence [AC] [BC] Links between A and B, holding C fixed

An analyst often starts from a simple model and adds terms that the shading suggests. A well-fitting model leaves mostly unshaded tiles.[7]

The plot can also be built in stages as variables are added. At each stage a model is fitted to the table of the variables entered so far.[4]

Several charts share the mosaic plot's use of area or its splitting method.

Chart How it relates to a mosaic plot
100% stacked bar chart All columns have the same width, so it shows only the mix inside each group, not group size.[8]
Spine plot Bars keep the same height and their widths show counts. It equals a mosaic plot of one variable, and highlighting a second variable gives a two-way mosaic without gaps.[6]
Double-decker plot A variant that places the response variable last in the splitting order.[6]
Association plot Each cell's rectangle has height in proportion to the residual and width in proportion to the square root of the expected count, so its area is in proportion to observed minus expected.[6]
Treemap Splits a nested tree by area, and each node may be split by its own rule. In a mosaic plot every split at one level uses the same variable.[9]

Ben Shneiderman came up with the treemap by splitting the screen into rectangles in alternating horizontal and vertical directions, one level of a tree at a time.[1]

Marimekko charts

Uses

In business a Marimekko chart is a variable-width 100% stacked bar chart. It is often used as a market map showing sales by customer, product, region, or competitor.[3] A typical use sets each column's width to the size of a market and splits it into each company's share.[8]

Name

The name comes from the Marimekko design firm of Helsinki, Finland, whose bright fabrics the chart resembles.[2] The same layout also goes by matrix chart, stacked spinogram, olympic chart, submarine chart, and Mekko chart.[2]

Color

Marimekko charts usually color each segment by its category.[10] Statistical mosaic plots may instead use color for residuals, as described in "Shading by residuals".[1]

History

The use of rectangle area to show a quantity is far older than the name "mosaic plot". Friendly traced the main steps.[1]

Year Person Contribution
1693 Edmond Halley Earliest known diagram using a rectangle's area (height times width) to show a quantity, the chances of survival and death for two independent lives
1844 Charles Joseph Minard Divided bars of varying width for freight on French canals, with width for distance, height for amount of goods, and area for transport cost
1877 Georg von Mayr Earliest known mosaic in modern form, splitting 1,000 cases into groups of 600, 300, and 100, then splitting each by a second variable
1896 Jacques Bertillon Map of Paris using rectangles whose height showed population and width the percent of foreign-born residents in 1891
1977 Jacques Bertin The "weighted matrix" (la matrice pondérée), which has most features of present-day mosaics
1981 John Hartigan and Beat Kleiner "Mosaics for Contingency Tables", the work the modern mosaic display is usually credited to
1994 Michael Friendly Shading by residuals and reordering of categories

Von Mayr titled his diagram "Area diagram with two splittings". This hints that he thought of further splits, though it is not clear whether he intended more variables.[1]

Much of the later interest in mosaic plots came from their use with count data (data recorded as counts of cases) and log-linear models.[1]

Strengths and limitations

Supporters point to several strengths.

  • Friendly argues that area is a natural way to show counts.[1]
  • He also argues that mosaic plots are strongest at complex tasks, such as judging patterns, trends, and unusual values, more than at reading single values.[1]
  • Mosaic plots extend to tables with many variables.[4]

Critics point to limits of reading areas. The data visualization writer Stephen Few lists several problems.[5]

  • People judge and compare 2-D areas poorly.
  • Tiles with the same area can have very different shapes, which makes comparison harder.
  • Height and width are hard to read separately, because the eye sees them together as area.
  • Tiles that do not share a common baseline are hard to compare by height.

Few concludes that a set of side-by-side bar charts can show the same relationships more clearly.[5]

Software

Base R includes a mosaicplot() function, and the vcd package provides mosaic() with residual shading.[6] The following draws the hair and eye data with shading.[7]

library(vcd)
haireye <- margin.table(HairEyeColor, c(1, 2))
mosaic(haireye, shade = TRUE)

Business tools also draw Marimekko charts. Tableau 10, released in 2016, added control over bar widths that made the chart easier to build.[2]

References

  1. A Brief History of the Mosaic Display, Michael Friendly, Journal of Computational and Graphical Statistics, 2002.
  2. Intro to Marimekko Charts: Part 1 of 3, Jonathan Drummey, Tableau, 2016.
  3. Marimekko Chart/Mekko Chart, Mekko Graphics, 2014.
  4. Mosaics: About Mosaic Displays, Michael Friendly, York University.
  5. Are Mosaic Plots Worthwhile?, Stephen Few, Perceptual Edge, 2014.
  6. The Strucplot Framework: Visualizing Multi-way Contingency Tables with vcd, David Meyer, Achim Zeileis, and Kurt Hornik, Journal of Statistical Software, 2006.
  7. Loglinear Models and Mosaic Displays (lecture notes), Michael Friendly, York University.
  8. What Is a Marimekko Chart? Uses and Examples, Domo.
  9. Understanding Area Based Plots: Mosaic Plots, Martin Theus, 2011.
  10. The Marimekko (mosaic) chart, Datashow.

Figure