0
$\begingroup$

Histogram[{3, 3, 2, 2, 2, 2, 2, 1, 1}] works great to give you an histogram in which mathematica counts the occurence of each number and makes the plot. Is there a variant for non-numeric data? Say I want to count and make an histogram on strings

Histogram[{"a", "a", "b", "c"}]

or even more general

Histogram[{a, a, b, c}]

where a,b, and c are (so far unassigned) symbols.

Is there a way to get this histogram from built-in functions?

$\endgroup$
7
$\begingroup$
BarChart[Counts[{"a", "a", "b", "c"}], ChartLabels -> Automatic]

enter image description here

By using Counts instead of Tally, we get an Association that BarChart knows how to handle automatically.

| improve this answer | |
$\endgroup$
0
$\begingroup$
Block[{t = Tally[{"a", "a", "b", "c"}]},
 BarChart[t[[All, 2]], ChartLabels -> t[[All, 1]]
  ]]

Mathematica graphics

| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.