Wolfram Language Paclet Repository

Community-contributed installable additions to the Wolfram Language

Primary Navigation

    • Cloud & Deployment
    • Core Language & Structure
    • Data Manipulation & Analysis
    • Engineering Data & Computation
    • External Interfaces & Connections
    • Financial Data & Computation
    • Geographic Data & Computation
    • Geometry
    • Graphs & Networks
    • Higher Mathematical Computation
    • Images
    • Knowledge Representation & Natural Language
    • Machine Learning
    • Notebook Documents & Presentation
    • Scientific and Medical Data & Computation
    • Social, Cultural & Linguistic Data
    • Strings & Text
    • Symbolic & Numeric Computation
    • System Operation & Setup
    • Time-Related Computation
    • User Interface Construction
    • Visualization & Graphics
    • Random Paclet
    • Alphabetical List
  • Using Paclets
    • Get Started
    • Download Definition Notebook
  • Learn More about Wolfram Language

MosaicPlot

Tech Notes

  • Mosaic plots for data visualization
  • Mosaic plots for numerical variables via categorical mapping

Symbols

  • MakeTooltipTable
  • MosaicPlot
Mosaic plots for numerical variables via categorical mapping
In this notebook we show how to transform numerical variables into categorical in order to get more informative mosaic plots.
Load the paclet
In[52]:=
Needs["AntonAntonov`MosaicPlot`"]
Here we get the Titanic dataset:
In[53]:=
dsTitanic=ResourceFunction["ExampleDataset"][{"MachineLearning","Titanic"}]
Out[53]=
passenger class
passenger age
passenger sex
passenger survival
1st
29.0
female
survived
1st
0.9167
male
survived
1st
2.0
female
died
1st
30.0
male
died
1st
25.0
female
died
1st
48.0
male
survived
1st
63.0
female
survived
1st
39.0
male
died
1st
53.0
female
survived
1st
71.0
male
died
1st
47.0
male
died
1st
18.0
female
survived
1st
24.0
female
survived
1st
26.0
female
survived
1st
80.0
male
survived
1st
—
male
died
1st
24.0
male
died
1st
50.0
female
survived
1st
32.0
female
survived
1st
36.0
male
died
rows 1–20 of
1309
Here is a mosaic plot of passenger class vs. passenger age:
In[54]:=
MosaicPlot
[dsTitanic[All,{"passenger class","passenger age"}]]
Out[54]=
The plot is not very informative
Here we make a mapping function of the numerical variable "passenger age" into "categorical age" integers (factors):
In[55]:=
factor=Piecewise[{{1,-Infinity<##1≤5},{2,5<##1≤14},{3,14<##1≤21},{4,21<##1≤28},{5,28<##1≤35},{6,35<##1≤50},{7,50<##1≤Infinity}},0]&;
Here we make a list of rules that map the categorical integers (factors) into (informative) labels:
In[56]:=
aFactorLabel={1"1(under 6)",2"2(6...14)",3"3(15...21)",4"4(22...]28)",5"5(29...35)",6"6(36...50)",7"7(50+)",0"0(missing)"};
Here we add the column "AgeFactor" that has the mapped values of "passenger age":
In[57]:=
dsTitanic2=dsTitanic[All,#,"AgeFactor"If[Head[#["passenger age"]]===Missing,0,factor[#["passenger age"]]]/.aFactorLabel&];
Here is the mosaic plot of passenger class vs. categorical passenger age:
In[59]:=
MosaicPlot
[dsTitanic2[All,{"passenger class","AgeFactor"}],"LabelRotation"{1,0.5},ImageSizeMedium]
Out[59]=
The second mosaic plot is more informative.
​
​
""

© 2025 Wolfram. All rights reserved.

  • Legal & Privacy Policy
  • Contact Us
  • WolframAlpha.com
  • WolframCloud.com