6
$\begingroup$

DistributionChart automatically puts a Tooltip on the elements of the chart, which shows the Min, 25%, Median, 75% and Max of the data. I would like to add the count of how many elements are in the set, to this.

Some data:

data = Table[RandomVariate[NormalDistribution[], n], {n, {10, 100, 1000}}];

DistributionChart[data]

Is there a way to do this?

$\endgroup$
7
$\begingroup$

You can post-process the output of DistributionChart to modify the content of tooltips:

Module[{i = 1}, DistributionChart[data] /. 
  Grid[x_, o__] :> Grid[Prepend[x, {Style["count", Bold], Length[data[[i++]]]}], o]]

enter image description here

Alternatively, you can wrap each data set with Tooltip using the second argument to specify tooltip content:

ClearAll[toolTip]
toolTip = Tooltip[#, Grid[Transpose[{Style[#, Bold] & /@ 
    {"count", "max", "75%", "median", "25%", "min"}, 
  {Item[Length@#, Alignment -> Center], ##&@@Reverse @ Quantile[#, {0, 1/4, 1/2, 3/4, 1}]}}],
 Dividers -> GrayLevel[.3], Alignment -> {{Center, ".", {Left}}}, 
 Frame -> Black, BaseStyle -> AbsoluteThickness[1]]] &;

DistributionChart[toolTip /@ data]

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.