I have some data which I want to plot in a simple bar chart:
example = {{"Knowledge", 2}, {"Comprehension", 4}, {"Application", 0}, {"Analysis", 1}, {"Synthesis", 0}, {"Evaluation", 2}}
The first element of each pair should be the bar label, and the second should be the height of the bar. I can get the desired result using:
BarChart[Last[#] & /@ example, ChartLabels -> {"Knowledge","Comprehension","Application","Analysis","Synthesis","Evaluation"}]
But my real question is this:
Though
First[#] &/@ example
Returns
{"Knowledge", "Comprehension", "Application", "Analysis", "Synthesis", "Evaluation"}
When I try:
BarChart[Last[#]&/@example, ChartLabels->First[#]&/@example]
I get a graph without labels:
This seems like strange behaviour, can anyone shed some light, or suggest a fix?
ChartLabels -> First[#] & /@ example
is doing. You need a bracket around the second part:ChartLabels -> (First[#] & /@ example)
$\endgroup$BarChart[Last /@ example, ChartLabels -> First /@ example]
orBarChart[example[[All, 2]], ChartLabels -> example[[All, 1]]]
. $\endgroup$