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.

  • $\begingroup$ Have you tried anything already? Please post code to show what you want and where you are stuck. $\endgroup$
    – Yves Klett
    Oct 16, 2013 at 13:52

1 Answer 1

tallydata = SortBy[Tally[data], First];
BarChart[tallydata[[All, 2]], ChartLabels -> (tallydata[[All, 1]])]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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