Mosaic plot
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]
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]
- Start with a square that stands for all the cases.
- Split it into vertical bars, one per category of the first variable. Each bar's width is in proportion to that category's total.
- 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.
- 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]
Spotting a link between variables
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 (an eye color) and column (a hair color):
- is the expected count in that cell.
- is the total of row , and is the total of column .
- is the total number of cases.
This formula explains why the tiles align. A tile's height within column is , and if every count equals its expected count, that height is in every column. This is the share of eye color in the whole sample, so it does not depend on the column.
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]
Here is the observed count and 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 . The observed count is 94, so the residual is . 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 , the cuts are:[7]
- first variable: widths in proportion to ,
- second variable: heights in proportion to ,
- third variable: widths in proportion to .
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]
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]
Related charts
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
- A Brief History of the Mosaic Display, Michael Friendly, Journal of Computational and Graphical Statistics, 2002.
- Intro to Marimekko Charts: Part 1 of 3, Jonathan Drummey, Tableau, 2016.
- Marimekko Chart/Mekko Chart, Mekko Graphics, 2014.
- Mosaics: About Mosaic Displays, Michael Friendly, York University.
- Are Mosaic Plots Worthwhile?, Stephen Few, Perceptual Edge, 2014.
- The Strucplot Framework: Visualizing Multi-way Contingency Tables with vcd, David Meyer, Achim Zeileis, and Kurt Hornik, Journal of Statistical Software, 2006.
- Loglinear Models and Mosaic Displays (lecture notes), Michael Friendly, York University.
- What Is a Marimekko Chart? Uses and Examples, Domo.
- Understanding Area Based Plots: Mosaic Plots, Martin Theus, 2011.
- The Marimekko (mosaic) chart, Datashow.
