8
$\begingroup$

I would like to make a following chart

BoxWhiskerChart with log y-axis

Ideally I would also like to control the boxes position on a logarithmic x-axis.

Some inspiration how to do the latter may be found in the answer to my other question: How to controll position on the x-axis of a boxWhiskerChart

TIA:)

$\endgroup$
3
  • $\begingroup$ Seems like you'll have to build such a plot from scratch, I see no easy way to use the existing functionality. This means working directly with Graphics primitives to construct the display. $\endgroup$
    – Jens
    Jan 31, 2013 at 18:59
  • $\begingroup$ @Jens crap. How come gnuplot has it and mathematica don't. $\endgroup$
    – JohnnyM
    Jan 31, 2013 at 19:55
  • $\begingroup$ @Jens there is a way: the option ScalingFunctions. I've added an answer detailing how it works. $\endgroup$
    – rcollyer
    Feb 1, 2013 at 3:05

2 Answers 2

15
$\begingroup$

Buried in the Details section of the documentation for BoxWhiskerChart is a reference to an option called ScalingFunctions which when set "the data coordinate is scaled using s." So, first some data:

data = RandomVariate[RayleighDistribution[RandomInteger[500]], {8, 50}];

without the scaling functions:

BoxWhiskerChart[data, "Outliers", ChartStyle -> 56]

Mathematica graphics

and with ScalingFunctions set to "Log":

BoxWhiskerChart[data, "Outliers", ChartStyle -> 56, ScalingFunctions -> "Log"]

Mathematica graphics

You might need a custom list of FrameTicks to get the desired formatting. Some ideas to get you started can be found here, here and here.

$\endgroup$
5
  • $\begingroup$ Great find (+1)! $\endgroup$
    – Jens
    Feb 1, 2013 at 5:28
  • $\begingroup$ @Jens thanks. I've been staring at these functions for a bit now, and sometimes interesting things appear. $\endgroup$
    – rcollyer
    Feb 1, 2013 at 5:33
  • $\begingroup$ Exacly what I was looking for! Awesome answer! $\endgroup$
    – JohnnyM
    Feb 1, 2013 at 14:05
  • $\begingroup$ This solution (ScalingFunctions) unfortunately doesn't work with the numbers less than 1(( $\endgroup$
    – user10232
    Dec 11, 2013 at 10:36
  • $\begingroup$ @MaxSakharov I see the issue in v9.0.1, but it appears to work correctly in the internal betas. So, if you need the feature, I would advise upgrading when the next version comes out. $\endgroup$
    – rcollyer
    Dec 11, 2013 at 12:56
2
$\begingroup$

Here is an example using the commercial Presentations package (which I develop).

<<Presentations`

Here are some data sets defined by their Log10 values.

data[1] = Array[RandomReal[{0, 1}] &, 10];
data[2] = Array[RandomReal[{0, 1.5}] &, 10];
data[3] = Array[RandomReal[{-1, 1}] &, 10];
data[4] = Array[RandomReal[{-0.5, 0.5}] &, 10];
data[5] = Array[RandomReal[{-0.5, 1}] &, 10];

Here is the BoxWhisker plot code.

xticks = CustomTicks[Identity, 
   databased[{{1, "CMEE"}, {2, "CUL"}, {3, "SR"}, {4, "DR"}, {5, 
      "AC"}}]];
yticks = CustomTicks[
   Log10, {-1, 2, {1, 2, 5} // N, {3, 4, 6, 7, 8, 9}}];
Draw2D[
 {{Dotted, Line[{{0, Log10[1]}, {6, Log10[1]}}]},
  ({BoxWhiskerDraw[data[#],
         ChartStyle -> 
          Directive[FaceForm[Opacity[0.2, Blue]], EdgeForm[Black], 
           Thin]],
        CirclePoint[{0, #}, 3, Black, White] & /@ data[#]} // 
       ScaleOp[{1, 1}, {0, 0}] // TranslateOp[{#, 0}]) & /@ Range[5]},
 AspectRatio -> 0.8,
 Frame -> True,
 FrameTicks -> {{yticks, yticks // NoTickLabels}, {xticks, 
    xticks // NoTickLabels}},
 PlotLabel -> Style["BoxWhisker Chart with Log Y Scale", 13, Bold],
 ImageSize -> 400]

And here is the plot:

Mathematica graphics

$\endgroup$

Your Answer

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

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