1
$\begingroup$

I have a non-numerical data, let say

data = Table[RandomChoice[{0.2, 0.3, 0.25, 0.15, 0.1} -> {"A", "B", "C", "D", "E"}], {500}];

and i want to make a histogram for this data. My solution so far

datanew = data;
label = Sort@DeleteDuplicates[data];
Do[datanew = ReplaceAll[datanew, label[[i]] -> i], {i, 1, Length[label]}]
Histogram[datanew, Ticks -> {None, Automatic}, ChartLabels -> {None, Placed[label, Below]}]

Is there any better way to do this? Thank you.

$\endgroup$
  • $\begingroup$ Have you tried anything already? Please post code to show what you want and where you are stuck. $\endgroup$ – Yves Klett Oct 16 '13 at 13:52
6
$\begingroup$
tallydata = SortBy[Tally[data], First];
BarChart[tallydata[[All, 2]], ChartLabels -> (tallydata[[All, 1]])]

enter image description here

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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