# How to use PairedBarChart to compare two BoxWhiskerCharts?

I have a time-series of BoxWhiskerCharts comparing two variables.

SeedRandom[23];
data1 = RandomReal[{0, 3}, 50];
data2 = RandomReal[{0, 4}, 50];
data3 = RandomReal[{0, 2}, 50];
data4 = RandomReal[{0, 1}, 50];
data5 = RandomReal[{0, 1}, 50];
data6 = RandomReal[{0, 1}, 50];
bw1 = BoxWhiskerChart[{data1, data2, data3}];
bw2 = BoxWhiskerChart[{data4, data5, data6}];
Row[{bw1, bw2}]


{data1, data2, data3} is a time-series of variable 1 and {data4, data5, data6} is for variable 2. I like to put the two box-whisker charts (BWC) next to each other to visually inspect the differences. But to do that, the x-y axes need to be standardized since the two variables take on values from different intervals. Namely, the charts need to be standardized in terms of the ranges of the axes.

How can I create such a BWC including two time-series charts?

• Under Possible Issues it is stated that: PairedBarChart does not accept negative values. Could you please say how you would like to rescale your values?
– Syed
Commented Dec 19, 2022 at 16:19
• @Sayed: One may generate only positive random numbers. In the case I have, all the numbers are positive. You may just replace 0 for -1. This would answer your question. I revised the sample code replacing 0. Commented Dec 19, 2022 at 16:36

SeedRandom[23];
data1 = RandomReal[{0, 3}, 50];
data2 = RandomReal[{0.5, 4}, 50];
data3 = RandomReal[{2.5, 4}, 50];
data4 = RandomReal[{0.5, 1.2}, 50];
data5 = RandomReal[{1, 4}, 50];
data6 = RandomReal[{2, 5}, 50];

bw1 = BoxWhiskerChart[{data1, data2, data3}, BarOrigin -> Left,
ImageSize -> Medium];
bw2 = BoxWhiskerChart[{data4, data5, data6}, BarOrigin -> Left,
ImageSize -> Medium, ScalingFunctions -> "Reverse"];
Show[{bw1, bw2}, Axes -> True,
AxesStyle -> {{Dotted, Gray}, {Dashed, Gray}}]


EDIT 1

Main change: Use BarOrigin->Right instead of Reverse as the ScalingFunctions. The interaction between and the incompatibility among various options has stranded me here.

bw1 = BoxWhiskerChart[{data1, data2, data3}
, BarOrigin -> Left
, ImageSize -> Medium
, Frame -> {{False, True}, {True, False}}
, Epilog -> {Gray, Dashed, InfiniteLine[{{0, -1}, {0, 1}}]
}
];
bw2 = BoxWhiskerChart[{data4, data5, data6}
, BarOrigin -> Right
, ImageSize -> Medium
, Frame -> {{True, False}, {True, False}}
, ChartLabels -> {"a", "b", "c"}
];
GraphicsRow[{bw2, bw1}, Spacings -> {-26, 0}]


• This is what aimed to develop!!! Thanks a lot. Commented Dec 20, 2022 at 16:25

Will a single chart work?

BoxWhiskerChart[{{data1, data2, data3}, {data4, data5, data6}},
ChartLabels -> {{"Set 1", "Set 2"}, None}]


• A single chart will not work in my case because it is almost impossible to compare pair-wise BWCs. I want to compare the first BWC in set 1 with the first BWC in set 2. The way you present is not really convenient. Commented Dec 19, 2022 at 16:33
• @TugrulTemel Doesn't Rohit's answer give you the solution: BoxWhiskerChart[{{data1, data4}, {data2, data5}, {data3, data6}}, ChartLabels -> {{"Time 1", "Time 2", "Time 3"}, None}].
– JimB
Commented Dec 19, 2022 at 16:47
• @JimB: No, it does not give the answer. I wanted to put the comparison in the format of PairedBarChart so that I can see the evolution of changes in a time-path. My specific question is whether one can create PairedBarChart or not. Commented Dec 19, 2022 at 17:07
• @JimB: Sorry to remind the exact question stated in the title of my question. Commented Dec 19, 2022 at 17:15

When one has data with multiple features that you want to display, the answer (in my opinion) is to produce separate figures for each feature. But journals (somewhat understandably) typically prefer a single figure.

Your data has two sources and change over time. With the very slight modification of @RohitNamjoshi 's answer one can see a reasonable compromise showing both features:

BoxWhiskerChart[{{data1, data4}, {data2, data5}, {data3, data6}},
ChartLabels -> {{"Time 1", "Time 2", "Time 3"}, None}]


But you seem to want (and maybe I still don't understand exactly what you want) to have a figure that resembles a PairedBarChart. A PairedBarChart has a common base for the bars at zero and with real data shown as box plots there is no common base. What one gets is something like the following:

Row[{BoxWhiskerChart[{data1, data2, data3},
ChartLabels -> {{"Time 1", "Time 2", "Time 3"}, Automatic},
BarOrigin -> Left, ImageSize -> Medium,
PlotRange -> {{0, 4}, {0.5, 3.5}},
PlotLabel -> Style["Data source 1", 18, Bold]],
BoxWhiskerChart[{data4, data5, data6},
ChartLabels -> {{"Time 1", "Time 2", "Time 3"}, Automatic},
BarOrigin -> Left, ImageSize -> Medium,
PlotRange -> {{0, 4}, {0.5, 3.5}},
PlotLabel -> Style["Data source 2", 18, Bold]]}]


Even if the extra space in the right-hand side is removed, this figure looks pretty awkward. And if you've got more than 30 points per data source/time period, then something like overlayed SmoothHistogram's would be more informative and take less ink.

• Yes, this is the graph I was imagining to create. Thanks. Commented Dec 19, 2022 at 17:52
• The origin 0 of the graph of the one on the left should be adjacent to the origin 0 of the graph on the right hand side for purposes of comparison. Commented Dec 19, 2022 at 19:00
• I won't do that so you should take off the accept. That would make the "trend" look in opposite directions and cause confusion. @RohitNamjoshi 's display is still the best for displaying the data with the structure you have.
– JimB
Commented Dec 19, 2022 at 19:08