Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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:)

share|improve this question
    
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. –  Jens Jan 31 '13 at 18:59
    
@Jens crap. How come gnuplot has it and mathematica don't. –  JohnnyM Jan 31 '13 at 19:55
    
@Jens there is a way: the option ScalingFunctions. I've added an answer detailing how it works. –  rcollyer Feb 1 '13 at 3:05
add comment

2 Answers

up vote 13 down vote accepted

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.

share|improve this answer
    
Great find (+1)! –  Jens Feb 1 '13 at 5:28
    
@Jens thanks. I've been staring at these functions for a bit now, and sometimes interesting things appear. –  rcollyer Feb 1 '13 at 5:33
    
Exacly what I was looking for! Awesome answer! –  JohnnyM Feb 1 '13 at 14:05
    
This solution (ScalingFunctions) unfortunately doesn't work with the numbers less than 1(( –  Max Sakharov Dec 11 '13 at 10:36
    
@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. –  rcollyer Dec 11 '13 at 12:56
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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