2
$\begingroup$

I would like to add a numeric label below each box in a grouped BoxWhiskerChart. I know how to do this in the ungrouped case, but cannot for the grouped case.

For example, the following generates four pairs of data blocks and plots these,

data = Table[RandomVariate[NormalDistribution[a, 1], 100], {a, {0, 3, 2, 5}}, {2}];

BoxWhiskerChart[data, ChartStyle -> {{Red, Green, Blue, Black}, None}, 
          ChartLabels -> {Placed[{1, 2, 3, 4}, Axis], None}]

which produces a plot like,

enter image description here

However let's say I want to add a specific number below each box. For example,

lNums = {5,10,15,4,7,8,1,3};

How can I do this in this case?

Note: I know I can do this manually but I was looking for a dynamic solution that will work when the data changes.

$\endgroup$
3
$\begingroup$

Here are a couple possibilities:

data = Table[
    RandomVariate[NormalDistribution[a,1], 100],
    {a,{0,3,2,5}}, {2}
];
labels = Partition[{5,10,15,4,7,8,1,3}, 2];

BoxWhiskerChart[
    data,
    ChartStyle->{{Red,Green,Blue,Black},None},
    LabelingFunction->(Placed[Extract[labels,#2],Below]&),
    ChartLabels->{Placed[{1,2,3,4},Axis],None}
]

(* or *)

BoxWhiskerChart[
    MapIndexed[Labeled[#,Extract[labels,#2],Below]&, data,{2}],
    ChartStyle->{{Red,Green,Blue,Black},None},
    ChartLabels->{Placed[{1,2,3,4},Axis],None}
]

enter image description here

I didn't show both charts, as they look the same.

$\endgroup$
0
$\begingroup$
SeedRandom[1]
data = Table[RandomVariate[NormalDistribution[a, 1], 100], {a, {0, 3, 2, 5}}, {2}];
lNums = {5, 10, 15, 4, 7, 8, 1, 3};
labels = Partition[lNums, 2];

labeleddata = Labeled[##, "LowerFence"]&@@@# & /@ (Transpose/@Transpose[{data, labels}]);

(You can also use Below in place of "LowerFence" above.)

BoxWhiskerChart[labeleddata, 
 ChartStyle -> {{Red, Green, Blue, Black}, None}, 
 ChartLabels -> {Placed[{1, 2, 3, 4}, Axis], None}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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