# BarChart with Log-Scaling and Error-Bars [duplicate]

I want to make a BarChart with Log-Scaling and Error-Bars.

I can do both individually:

TimeData = {3.33523 -> 2.72453, 1.14286 -> 0.74611, 1.02783 -> 0.815587, 3.6301 -> 2.42748}
BarChart[TimeData, ScalingFunctions -> "Log"]
BarChart[TimeData, ChartElementFunction -> errorBar["Rectangle"]]


And it gives me the expected results, but as soon as I add the two parameters together, i.e.

BarChart[TimeData, ChartElementFunction -> errorBar["Rectangle"], ScalingFunctions -> "Log"]


the scaling is logarithmic, but the error-bars stay linear, thus make not much sense. Is there any clever way to do it?

(A nasty work-around would be to calculate the errors in a logarithmic way, and then the linear plot of them would give the correct result, but that's defintiivly not a nice way)

## marked as duplicate by NicoDean, bbgodfrey, Karsten 7., kglr plotting StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Feb 10 '15 at 16:18

The function errorBar can be found in the Documentation Center page How to -- Add Error Bars to Charts and Plots.

You can change the function errorBar to take a scaling function argument:

errorBar2[sf_: Identity, type_: "Rectangle"][{{x0_, x1_}, {y0_, y1_}}, value_, meta_] :=
Block[{error, isf = InverseFunction[sf][y1]}, error = Flatten[meta];
error = If[error == {}, {0, 0}, {sf[isf - #], sf[isf + #]} &@error];
{ChartElementData[type][{{x0, x1}, {y0, y1}}, value, meta],
{Thick, Dynamic@Darker@CurrentValue["Color"],
Line[{{{(x0 + x1)/2, error[[1, 1]]}, {(x0 + x1)/2, error[[2, 1]]}},
{{1/4 (3 x0 + x1), error[[2, 1]]}, {1/4 (x0 + 3 x1), error[[2, 1]]}},
{{1/4 (3 x0 + x1), error[[1, 1]]}, {1/4 (x0 + 3 x1), error[[1, 1]]}}}]}}]

Row[BarChart[TimeData, ScalingFunctions -> #, PlotLabel -> (Style[ScalingFunctions -> #, 16]),
ChartStyle -> "DarkRainbow", ImageSize -> 400,
ChartElementFunction -> errorBar2[ToExpression[# /. None->"Identity"], "GlassRectangle"]] & /@
{None, "Log"}, Spacer[10]]


• @kugler Thank you, that looks very good. One thing I wonder: The symmetric errors in the linear plot should appear non-linear (logarithmic) in the log-plot, right? But in your example, they also seem symmetric. Do you know why that is? – NicoDean Feb 10 '15 at 14:04
• @NicoDean, right -- Great observation! As is, errorBar produces symmetric errors, so does errorBar2. I will post an update with a fix. – kglr Feb 10 '15 at 14:30
• I was just searching for that problem (it seems to exist in every type of log-scale error plotting), and found a very similar question: mathematica.stackexchange.com/questions/35462/… (i didn't see it before when I was writing the question). The answer shows how to manually scale the errors. – NicoDean Feb 10 '15 at 14:34
• NicoDean, thank you for the link -- i was trying to do a similar modification. Since @ubpdqn's answer in the linked Q/A covers this question too, do you think this question should be marked as duplicate? – kglr Feb 10 '15 at 14:56
• Yes I guess so :-/ Sorry. And strange that it didn't show up earlier. – NicoDean Feb 10 '15 at 15:01