I am trying to create a pareto chart for some non technical folks and having the hardest time formatting it correctly…
Here’s my sample code:
(*Some dynamically generated data *)
mydata = {0.9436, 2.20725333345, 2.1402, 1.8729, 4.9436, 0.4819};
mylabels = {"l1", "l2", "l3", "l4", "some really long label", "another really long label", "l7"};
(*lets riffle and sort the data *)
a = Sort[ Partition[Riffle[mylabels, mydata], 2], #1[[2]] > #2[[2]] & ];
BarChart[a , BarOrigin -> Left, BarSpacing -> -1, LabelingFunction -> (Placed[#, After] &), Axes -> None, Frame -> True, FrameTicks -> None, FrameLabel -> "Some Title", GridLines -> None, AspectRatio -> 0.3, ImageSize -> Full, ChartStyle -> "Pastel"]
A few questions:
What is the best way to truncate to 2 digits in the labels, I tried using
NumberForm
in the Sort function but doesn’t work since Numberform is a wrapper.Labeling works reasonably well when labels are short but I seem to run into placement issues with long labels… Any ideas on better ways to handle this?
Frame produced by Mathematica seems to overlap with the labels…
Any suggestions gladly appreciated!
Answer
Here's one approach.
mydata = N[Round[{0.9436, 2.20725333345, 2.1402, 1.8729, 4.9436, 0.4819}*100]/100];
This will make the data appear with only 2 decimal places of accuracy. If you are willing to rearrange things a bit, it's pretty easy to remove the overlap...
BarChart[Labeled[#2, #1, Before] & @@@ a, BarSpacing -> 0,
LabelingFunction -> (Placed[#, After] &), BarOrigin -> Left,
PlotLabel -> "Some Title"]
This gives:
Comments
Post a Comment