2
$\begingroup$

DistributionChart does not show entries for sublists containing only one element. Although I can understand why this would be reasonable (there's no "distribution" of a single element), it seems that at least some of the display options such as "PointDensity" should at least plot the points in question.

For example:

data = {{39.}, {82.}, {97., 99.}, {112., 109., 115.}, {124., 126., 123.,128., 120.}};

DistributionChart[
 data,
 ChartElementFunction -> "PointDensity",
 ChartLabels -> Range[5]]

example of a DistributionChart result

shows the points associated with the sublists containing more than one element, but does not show any of the points in the first two sublists.

A hacky way to do get this to display is to add a duplicate entry to the single-member lists, e.g., redefining:

data = {{39.,39.}, {82.,82.}, {97., 99.}, {112., 109., 115.}, {124., 126., 123.,128., 120.}};

for the example above gives:

slightly better output

which at least shows something, although the presence of two points is undesirable.

Is there a better idiomatic way to shows these single points on this type of plot?

Using Show-ing with a ListPlot (as in this answer) seems even more complicated.

I suspect there's a way to do it by defining a special ChartElementFunction, but I don't understand graphics well enough.

$\endgroup$

1 Answer 1

2
$\begingroup$
  1. Replicate singleton data (as you did)
  2. Pass the original data as metadata and
  3. Use the metadata (#3[[1]]) as the second argument of the function "PointDensity"; that is, use ChartElementFunction -> ChartElementData["PointDensity"][#, #3[[1]]]&.

DistributionChart[Thread[(data /. {a_?NumericQ} :> {a, a}) -> data],
 ChartStyle -> "Rainbow", 
 ChartElementFunction ->
  (ChartElementData["PointDensity",  "PointStyle" -> 
       Directive[Black, PointSize[Medium]]][#, #3[[1]]] &), 
 ChartLabels -> Range[5]]

enter image description here

Update: We can use a custom ChartElementFunction to place points less randomly than the built-in "PointDensity" does:

ClearAll[cEF]
cEF[cf_: "Quantile", opts : OptionsPattern[]] := {ChartElementData[cf, opts][##], 
    Darker@Darker@Charting`ChartStyleInformation["Color"], 
    PointSize[Medium], 
    Point[Transpose[{Most @  Rest@Subdivide[#[[1, 1]], #[[1, 2]], 
          1 + Length[#3[[1]]]], #3[[1]]}]]} &;

Examples:

DistributionChart[Thread[(data /. {a_?NumericQ} :> {a, a}) -> data], 
 ChartStyle -> "Rainbow", 
 ChartElementFunction -> cEF[], 
 ChartLabels -> Range[5]]

enter image description here

Use ChartElementFunction -> cEF["SmoothDensity"] to get

enter image description here

$\endgroup$

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.