5
$\begingroup$
$Version
(* 12.3.1 for Mac OS X x86 (64-bit) (June 19, 2021) *)

data = <|"A" -> {40344, 30000, 30000}, "B" -> {82000, 85008}, "C" -> {98328}, "D" -> {45096, 41520, 42552}|>

BoxWhiskerChart[data, ChartLabels -> Placed[Style[#, Black] & /@ Keys@data, Above]]

enter image description here

There is just a single value for the key "C" so it is missing from the chart. Is there some way to display the label and e.g. a fence line or a plot marker at that value? Preferably not using Show to combine with ListPlot.

$\endgroup$
3
  • $\begingroup$ Maybe the other sample sizes of 2 and 3 are just for an example but if those are the actual sample sizes, then a Box and Whisker plot makes no sense for 2 and 3 data points just as much as id doesn't make sense for 1 data point. In that case just showing the data points gives the user a better display of what the data says. If the points overlap, just jitter them a bit. $\endgroup$
    – JimB
    Commented Nov 4, 2021 at 17:16
  • $\begingroup$ @JimB Most keys have 10 - 50 values, some have only 1 or 2. Just the nature of the data I am working with. $\endgroup$ Commented Nov 4, 2021 at 18:07
  • 1
    $\begingroup$ Got it. Then you are consistent with the comment of @whuber (one of the best) at stats.stackexchange.com/questions/194842/…. $\endgroup$
    – JimB
    Commented Nov 4, 2021 at 18:56

1 Answer 1

4
$\begingroup$

Hack:

data = <|"A" -> {40344, 30000, 30000}, "B" -> {82000, 85008}, 
   "C" -> {98328, 98328, 98328}, "D" -> {45096, 41520, 42552}|>;

BoxWhiskerChart[data, 
 ChartLabels -> Placed[Style[#, Black] & /@ Keys@data, Above], 
 PlotRangePadding -> {{0.1, 0.1}, {10000, 10000}}]

enter image description here

$\endgroup$
1
  • 2
    $\begingroup$ you can also do BoxWhiskerChart[ReplaceAll[{x_} :> {x, x}]@data, ChartLabels -> Placed[Automatic, Above]] where data is as in OP's original example (+1) $\endgroup$
    – kglr
    Commented Nov 4, 2021 at 22:06

Your Answer

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

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