5
$\begingroup$

Subcategories in different groups have different names.

How can I adjust the settings of ChartLabels? Or is there another way?

data = {{RandomInteger[{0, 100}, 100],
    RandomInteger[{0, 100}, 100]}, {RandomInteger[{0, 100}, 100],
    RandomInteger[{0, 100}, 100]}};
BoxWhiskerChart[data,
 ChartLabels -> {{"Group1", "Group2"}, {"a", "b", "c", "d"}}]

Enter image description here

Very confusing! Neither approach works if the number of subgroups is different!

data = {{RandomInteger[{0, 100}, 100],RandomInteger[{0, 100}, 100],
    RandomInteger[{0, 100}, 100]}, {RandomInteger[{0, 100}, 100],
    RandomInteger[{0, 100}, 100]}};
BoxWhiskerChart[data,
 ChartLabels -> {{"Group1", "Group2"}, {"a", "b", "c", "d", "e"}}]

Enter image description here

$\endgroup$
1

2 Answers 2

8
$\begingroup$
Clear["Global`*"]

SeedRandom[1234];

data = {
   {RandomInteger[{0, 100}, 100], 
    RandomInteger[{0, 100}, 100]}, 
   {RandomInteger[{0, 100}, 100], 
    RandomInteger[{0, 100}, 100]}};

colors = {
   RGBColor[0.982864, 0.7431472, 0.3262672], 
   RGBColor[0.4992, 0.5552, 0.8309304]};

BoxWhiskerChart[Flatten[data, 1],
 ChartStyle -> colors, ChartLabels -> {"a", "b", "c", "d"},
 Epilog -> {
   Text[Style["Group1", 9], Scaled@{0.28, -0.15}],
   Text[Style["Group2", 9], Scaled@{0.74, -0.15}]},
 ImagePadding -> {{Automatic, 5}, {30, 5}}]

enter image description here

$\endgroup$
8
$\begingroup$
SeedRandom[1]
data = {{RandomInteger[{0, 100}, 100], RandomInteger[{0, 100}, 100]}, 
  {RandomInteger[{0, 100}, 100], RandomInteger[{0, 100}, 100]}};

labels = TakeList[ {"a", "b", "c", "d"}, Length /@ data];

You can wrap each data series with Labeled to attach desired labels:

labeleddata = MapThread[Labeled] /@ Transpose[{data, labels}];

BoxWhiskerChart[labeleddata, ChartLabels -> {{"Group1", "Group2"}, Automatic}]

enter image description here

$\endgroup$
0

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.