WOLFRAM

Enable JavaScript to interact with content and submit forms on Wolfram websites. Learn how
Wolfram Language & System Documentation Center

CategoricalHistogram [{c1,c2,,cn}]

creates a histogram of the distinct categories in the list of categorical elements c1, c2, etc.

CategoricalHistogram [data,spec]

uses the specification spec to determine the categories.

CategoricalHistogram [data,spec,height]

uses the height value height to compare the bars.

CategoricalHistogram [{data1,data2,},]

plots histograms for multiple datasets datai.

Details
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Data and Layouts  
Tabular Data  
Wrappers  
Styling and Appearance  
Labeling and Legending  
Applications  
See Also
History
Cite this Page

CategoricalHistogram [{c1,c2,,cn}]

creates a histogram of the distinct categories in the list of categorical elements c1, c2, etc.

CategoricalHistogram [data,spec]

uses the specification spec to determine the categories.

CategoricalHistogram [data,spec,height]

uses the height value height to compare the bars.

CategoricalHistogram [{data1,data2,},]

plots histograms for multiple datasets datai.

Details

Examples

open all close all

Basic Examples  (7)

Generate a histogram for a list of categorical data:

Wolfram Language code: CategoricalHistogram[IconizedObject[«Cylinders per car»]]

Multiple datasets:

Wolfram Language code: CategoricalHistogram[{IconizedObject[«compact-class cylinders»], IconizedObject[«midsize-class cylinders»], IconizedObject[«subcompact-class cylinders»]}]

Use "CategoryLabels" to rename some of the resulting categories:

Wolfram Language code: data = <|"data one" -> <|"a" -> "dog", "b" -> "fish", "c" -> "fish", "d" -> "fish", "e" -> "cat", "f" -> "fish", "g" -> "cat", "h" -> "cat", "i" -> "fish", "j" -> "fish", "k" -> "fish", "l" -> "fish", "m" -> "fish"|>, "data two" -> <|"a" -> "cat", "b" -> "fish", "c" -> "cat", "d" -> "dog", "e" -> "cat", "f" -> "cat", "g" -> "cat", "h" -> "fish", "i" -> "cat", "j" -> "dog", "k" -> "cat", "l" -> "cat", "m" -> "cat"|>|>;
Wolfram Language code: CategoricalHistogram[data, <|"CategoryLabels" -> <|"cat" -> "CAT", "dog" -> "DOG"|>|>]

For individual data, set the style for each of the bars:

Wolfram Language code: CategoricalHistogram[IconizedObject[«Cylinders per car»], PlotStyle -> "DarkRainbow"]

in case of multiple datasets, the style set is based on the dataset where categories come from:

Wolfram Language code: CategoricalHistogram[{IconizedObject[«compact-class cylinders»], IconizedObject[«midsize-class cylinders»], IconizedObject[«subcompact-class cylinders»]}, PlotStyle -> "DarkRainbow"]

Use PlotStyle {style,None } to use the color scheme per category instead:

Wolfram Language code: CategoricalHistogram[{IconizedObject[«compact-class cylinders»], IconizedObject[«midsize-class cylinders»], IconizedObject[«subcompact-class cylinders»]}, PlotStyle -> {"DarkRainbow", None}]

Use pictorial bars:

Wolfram Language code: CategoricalHistogram[IconizedObject[«Cylinders per car»], ChartElements -> [image]]

Use different layouts:

Wolfram Language code: Table[CategoricalHistogram[{IconizedObject[«compact-class cylinders»], IconizedObject[«midsize-class cylinders»], IconizedObject[«subcompact-class cylinders»]}, PlotLabel -> l, ChartLayout -> l], {l, {"Percentile", "Stacked"}}]

Scope  (28)

Data and Layouts  (15)

Which bins to use is automatically determined:

Wolfram Language code: CategoricalHistogram[IconizedObject[«Cars per fuel type»]]

Specify which categories/bins to use:

Wolfram Language code: CategoricalHistogram[IconizedObject[«Cars per fuel type»], {"r", "p", "e"}]

Specify how many categories to use:

Wolfram Language code: CategoricalHistogram[IconizedObject[«Cars per fuel type»], 4]

Sort categories on the chart based on the values:

Wolfram Language code: CategoricalHistogram[IconizedObject[«Cars per fuel type»], <|"CategoryOrdering" -> "Increasing"|>]

Sort categories on the chart based on category names:

Wolfram Language code: CategoricalHistogram[IconizedObject[«Cars per fuel type»], <|"CategoryOrdering" -> "Alphabetic"|>]

Show just categories whose counts meet a minimum count threshold of 50:

Wolfram Language code: CategoricalHistogram[IconizedObject[«Cars per fuel type»], <|"MinimumBinCount" -> 50|>]

Show just categories whose counts meet a minimum percentage threshold of 22 percent:

Wolfram Language code: CategoricalHistogram[IconizedObject[«Cars per fuel type»], <|"MinimumBinFraction" -> .22|>]

Take categories using the default ordering until a minimum total percentage threshold is obtained:

Wolfram Language code: CategoricalHistogram[IconizedObject[«Cars per fuel type»], <|"MinimumTotalFraction" -> .95|>]

Take categories using a specific ordering until at least a minimum total percentage of 5 percent threshold is met:

Wolfram Language code: CategoricalHistogram[IconizedObject[«Cars per fuel type»], <|"CategoryOrdering" -> "Increasing", "MinimumTotalFraction" -> .05|>]

Change labels for specific categories:

Wolfram Language code: CategoricalHistogram[IconizedObject[«Cars per fuel type»], <|"CategoryLabels" -> <|"c" -> "Label 1", "d" -> "Label 2"|>|>]

Data that belongs to the same datasets across categories is styled the same:

Wolfram Language code: CategoricalHistogram[{IconizedObject[«compact-class cylinders»], IconizedObject[«midsize-class cylinders»], IconizedObject[«subcompact-class cylinders»]}, PlotLegends -> Automatic]
Wolfram Language code: CategoricalHistogram[<|"compact" -> IconizedObject[«compact-class cylinders»], "midsize" -> IconizedObject[«midsize-class cylinders»], "Subcompact" -> IconizedObject[«subcompact-class cylinders»]|>]

Associations can be nested:

Wolfram Language code: data = <|"data one" -> <|"a" -> "dog", "b" -> "fish", "c" -> "fish", "d" -> "fish", "e" -> "cat", "f" -> "fish", "g" -> "cat", "h" -> "cat", "i" -> "fish", "j" -> "fish", "k" -> "fish", "l" -> "fish", "m" -> "fish"|>, "data two" -> <|"a" -> "cat", "b" -> "fish", "c" -> "cat", "d" -> "dog", "e" -> "cat", "f" -> "cat", "g" -> "cat", "h" -> "fish", "i" -> "cat", "j" -> "dog", "k" -> "cat", "l" -> "cat", "m" -> "cat"|>|>;
Wolfram Language code: CategoricalHistogram[data]

Use keys as legends:

Wolfram Language code: CategoricalHistogram[data, ChartLegends -> Automatic]

Use different layouts to display multiple datasets:

Wolfram Language code: Table[CategoricalHistogram[{IconizedObject[«compact-class cylinders»], IconizedObject[«midsize-class cylinders»], IconizedObject[«subcompact-class cylinders»]}, PlotLabel -> l, ChartLayout -> l], {l, {"Percentile", "Stacked"}}]

Use "Overlapped" layout:

Wolfram Language code: CategoricalHistogram[{IconizedObject[«compact-class cylinders»], IconizedObject[«midsize-class cylinders»], IconizedObject[«subcompact-class cylinders»]}, PlotLabel -> "Overlapped", ChartLayout -> "Overlapped"]

Use rows and columns of individual plots to show multiple sets:

Wolfram Language code: CategoricalHistogram[{IconizedObject[«compact-class cylinders»], IconizedObject[«midsize-class cylinders»], IconizedObject[«subcompact-class cylinders»]}, ChartLayout -> "Column"]

Control the origin of bars:

Wolfram Language code: data = {"Cat", "Dog", "Rabbit", "Cat", "Rabbit", "Bird", "Rabbit", "Dog", "Dog", "Dog"}; Table[CategoricalHistogram[data, BarOrigin -> o, PlotLabel -> o, ImageSize -> Small], {o, {Bottom, Left, Top, Right}}]

Tabular Data  (1)

Get tabular data, with information about Titanic passengers, class and sex:

Wolfram Language code: titanic = ToTabular[ResourceData["Sample Data: Titanic Survival"]]

Create a Histogram for class of passengers:

Wolfram Language code: CategoricalHistogram[titanic -> "Class"]

See the counts of passengers grouped by Class and Sex:

Wolfram Language code: groupdata = GroupBy[titanic, #Class&, Normal[#[All, "Sex"]]&];
Wolfram Language code: CategoricalHistogram[groupdata, ChartLegends -> Automatic]

Use stacked bars for the display:

Wolfram Language code: CategoricalHistogram[groupdata, ChartLegends -> Automatic, ChartLayout -> "Stacked"]

Wrappers  (1)

Use wrappers on individual data:

Wolfram Language code: CategoricalHistogram[Style[IconizedObject[«compact-class cylinders»], StandardGreen]]

Styling and Appearance  (5)

Use an explicit style list for each category bin of the data:

Wolfram Language code: CategoricalHistogram[IconizedObject[«Male Palmer Penguins Species»], PlotStyle -> 60]

Use explicit color types that belong to the same dataset:

Wolfram Language code: CategoricalHistogram[{IconizedObject[«Female Palmer Penguins Species»], IconizedObject[«Male Palmer Penguins Species»]}, PlotStyle -> {Red, Green}]

Use any gradient or indexed color schemes from ColorData :

Wolfram Language code: {CategoricalHistogram[{IconizedObject[«Female Palmer Penguins Species»], IconizedObject[«Male Palmer Penguins Species»]}, PlotStyle -> "Pastel"], CategoricalHistogram[{IconizedObject[«Female Palmer Penguins Species»], IconizedObject[«Male Palmer Penguins Species»]}, PlotStyle -> {"Pastel", None}]}

ChartBaseStyle can be used to set an initial style for all chart elements:

Wolfram Language code: CategoricalHistogram[{IconizedObject[«Female Palmer Penguins Species»], IconizedObject[«Male Palmer Penguins Species»]}, ChartBaseStyle -> EdgeForm[Dotted]]

Use any graphic for pictorial bars:

Wolfram Language code: CategoricalHistogram[IconizedObject[«Male Palmer Penguins Species»], ChartElements -> Graphics[{Red, Circle[]}]]

Use built-in, programmatically generated bars:

Wolfram Language code: ChartElementData["Histogram"]
Wolfram Language code: Table[CategoricalHistogram[IconizedObject[«Male Palmer Penguins Species»], ChartElementFunction -> f], {f, {"GlassRectangle", "GradientScaleRectangle"}}]

For detailed settings, use Palettes ChartElementSchemes:

Wolfram Language code: CategoricalHistogram[IconizedObject[«Male Palmer Penguins Species»], ChartElementFunction -> ChartElementDataFunction["SegmentScaleRectangle", "Segments" -> 7, "ColorScheme" -> "SolarColors"]]

Use a monochrome theme:

Wolfram Language code: CategoricalHistogram[IconizedObject[«Male Palmer Penguins Species»], PlotTheme -> "Monochrome"]

Labeling and Legending  (6)

Provide value labels for bars by using LabelingFunction :

Wolfram Language code: CategoricalHistogram[IconizedObject[«compact-class cylinders»], LabelingFunction -> Above]

ChartElements may override settings for PlotStyle :

Wolfram Language code: CategoricalHistogram[IconizedObject[«compact-class cylinders»], ChartElements -> [image], PlotStyle -> {RGBColor[0.93, 0.27, 0.27], RGBColor[0.14, 0.8, 0.14], RGBColor[0.4, 0.6, 1]}]

Use Placed within a custom function to control placement and formatting:

Wolfram Language code: labeler[v_, {i_, j_}, {ri_, cj_}] := Placed[{StringJoin[ToString[First@cj], "-cyl"], v}, Above, Column]
Wolfram Language code: CategoricalHistogram[IconizedObject[«compact-class cylinders»], LabelingFunction -> labeler]

Add categorical legend entries for categories:

Wolfram Language code: CategoricalHistogram[IconizedObject[«compact-class cylinders»], ChartLegends -> {"Cat1", "Cat2", "Cat3"}, PlotStyle -> "Pastel"]

Use Association based PlotStyle to indicate categories

Wolfram Language code: CategoricalHistogram[IconizedObject[«compact-class cylinders»], ChartLegends -> {"Cat1", "Cat2", "Cat3"}, PlotStyle -> <|"Categories" -> "Pastel"|>]
Wolfram Language code: CategoricalHistogram[{IconizedObject[«compact-class cylinders»], IconizedObject[«midsize-class cylinders»], IconizedObject[«subcompact-class cylinders»]}, PlotStyle -> <|"Categories" -> "Pastel"|>, PlotLegends -> <|"Categories" -> {"Cat1", "Cat2", "Cat3"}|>]

Add categorical legend entries for datasets:

Wolfram Language code: CategoricalHistogram[{IconizedObject[«compact-class cylinders»], IconizedObject[«midsize-class cylinders»], IconizedObject[«subcompact-class cylinders»]}, ChartLegends -> {"Dataset1", "Dataset2", "Dataset3"}, PlotStyle -> "Pastel"]
Wolfram Language code: CategoricalHistogram[{IconizedObject[«compact-class cylinders»], IconizedObject[«midsize-class cylinders»], IconizedObject[«subcompact-class cylinders»]}, PlotStyle -> <|"Lists" -> "Pastel"|>, PlotLegends -> <|"Lists" -> {"Dataset1", "Dataset2", "Dataset3"}|>]

Use Placed to affect the positioning of legends:

Wolfram Language code: Table[CategoricalHistogram[{IconizedObject[«compact-class cylinders»], IconizedObject[«midsize-class cylinders»], IconizedObject[«subcompact-class cylinders»]}, ChartLegends -> Placed[{"ccc1", "ccc2", "ccc3"}, p], PlotStyle -> "Pastel"], {p, {Below, Above}}]

Applications  (5)

Analyze the prevalence of mushrooms across different habitats with some of its properties:

Wolfram Language code: table = ToTabular[ResourceData["Sample Data: Mushroom Classification"]]

Generate a histogram to see the edible quality of the mushrooms in the dataset:

Wolfram Language code: CategoricalHistogram[table -> "Class"]

Use GroupBy to split the data per habitat and if whether they are edible or not:

Wolfram Language code: classperhabitat = GroupBy[table, #Class&, Normal[#[All, "Habitat"]]&]; CategoricalHistogram[classperhabitat, BarSpacing -> {Automatic, 3.5}, PlotLegends -> Automatic]

For cases when categories are too large, use LabelingSize to display just a portion of the category:

Wolfram Language code: CategoricalHistogram[classperhabitat, BarSpacing -> {Automatic, 4}, PlotLegends -> Automatic, AspectRatio -> 1 / 2, LabelingSize -> 32]

Display the counts of diamonds by cut:

Wolfram Language code: tabulardata = ResourceData["Sample Tabular Data: Diamonds"];
Wolfram Language code: CategoricalHistogram[tabulardata -> "cut"]

Use GroupBy and CategoricalHistogram to display diamonds' counts of cuts split by color:

Wolfram Language code: groupdata = GroupBy[tabulardata, #cut&, Normal[#[All, "color"]]&];
Wolfram Language code: CategoricalHistogram[groupdata, ChartLegends -> Automatic]

Use "MinimumBinFraction" to show just categories whose counts represent at least 15% of the total counts:

Wolfram Language code: CategoricalHistogram[groupdata, <|"MinimumBinFraction" -> .15|>, ChartLegends -> Automatic]

Use "MaxCount" to emphasize the biggest categories with "RemainderCategory" to put all other elements into a single generic group:

Wolfram Language code: CategoricalHistogram[groupdata, <|"MaxCount" -> 2|>, ChartLegends -> Automatic]

Add "RemainderCategory" to put all the discarded elements into a single generic group, while keeping the original elements selected by "MaxCount":

Wolfram Language code: CategoricalHistogram[groupdata, <|"MaxCount" -> 2, "RemainderCategory" -> "Others"|>, ChartLegends -> Automatic]

Display the number of penguins in the Palmer Penguins dataset, grouped by island:

Wolfram Language code: tab = ResourceData["Sample Tabular Data: Palmer Penguins"]; data = GroupBy[tab, #sex&, Normal[#[All, "species"]]&];
Wolfram Language code: CategoricalHistogram[data, ChartLegends -> Automatic]

Compare the gender of patients who received a kidney transplant:

Wolfram Language code: kidneydata = ToTabular[ResourceData["Sample Data: Kidney Transplant"]]; CategoricalHistogram[kidneydata -> "Gender", ChartLegends -> Automatic]

Compare the data of patients who received a kidney transplant by gender and race:

Wolfram Language code: kidneydatabygenderandrace = GroupBy[kidneydata, #Gender&, Normal[#[All, "Race"]]&]; CategoricalHistogram[kidneydatabygenderandrace, ChartLegends -> Automatic]

Analyze from the tree census dataset the type of category of user who collected tree data:

Wolfram Language code: NYCTrees = ResourceData["Sample Tabular Data: NYC Trees"];
Wolfram Language code: CategoricalHistogram[NYCTrees -> "user_type", BarSpacing -> 2]

Compare the category of user per borough:

Wolfram Language code: NYCTreesbyusertype = GroupBy[NYCTrees, #"user_type"&, Normal[#[All, "borough"]]&];
Wolfram Language code: CategoricalHistogram[NYCTreesbyusertype, BarSpacing -> {Automatic, 4}, PlotLegends -> Automatic]
Wolfram Research (2026), CategoricalHistogram, Wolfram Language function, https://reference.wolfram.com/language/ref/CategoricalHistogram.html.

Text

Wolfram Research (2026), CategoricalHistogram, Wolfram Language function, https://reference.wolfram.com/language/ref/CategoricalHistogram.html.

CMS

Wolfram Language. 2026. "CategoricalHistogram." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/CategoricalHistogram.html.

APA

Wolfram Language. (2026). CategoricalHistogram. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CategoricalHistogram.html

BibTeX

@misc{reference.wolfram_2026_categoricalhistogram, author="Wolfram Research", title="{CategoricalHistogram}", year="2026", howpublished="\url{https://reference.wolfram.com/language/ref/CategoricalHistogram.html}", note=[Accessed: 18-August-2026]}

BibLaTeX

@online{reference.wolfram_2026_categoricalhistogram, organization={Wolfram Research}, title={CategoricalHistogram}, year={2026}, url={https://reference.wolfram.com/language/ref/CategoricalHistogram.html}, note=[Accessed: 18-August-2026]}

Top [フレーム]

AltStyle によって変換されたページ (->オリジナル) /