I'm looking for a way to produce a bar chart that will display the frequencies of letters in a given string which would include empty bars for any letter which isn't in the string.
BarChart[LetterCounts["GIVEN STRING GOES HERE"],
ChartLabels -> Automatic]
Almost does what I want, but I would like to have the entire English upper case alphabet, in alphabetical order, as the horizontal labels, and have empty bars where any letter is not contained in the given string.
Also, any way to turn this into a relative frequency bar chart? I.e. have the vertical measurements as count(letter)/count(total) instead of count(letter)
Thanks for any help!
One way to do this.
zeroCounts = Alphabet // ToUpperCase // AssociationThread[#, ConstantArray[0, 26]] &;
BarChart[zeroCounts~Join~LetterCounts["GIVEN STRING GOES HERE"], ChartLabels -> Automatic]
To get the relative counts, just scale the values in the LetterCounts association by the total of the values.
counts = LetterCounts["GIVEN STRING GOES HERE"];
scaledCounts = counts / (counts // Values // Total)
Perfect, thanks Rohit!