1
$\begingroup$

I would like to use the ChartElementFunction option of DistributionChart to plot data with a custom style that includes custom plot markers, such as open circles. I am struggling with the scaling of the markers, though.

If I use Points as plot markers, everything is fine:

data = Table[RandomReal[i + {1, 3}, 10], {i, 5}];

cef1[{{xmin_, xmax_}, {ymin_,ymax_}}, data_, metadata_]:=
    {Black, PointSize[Large], Point[{RandomReal[{xmin, xmax}], #}]& /@ data};

DistributionChart[data, ChartElementFunction -> cef1]

enter image description here

If I use Circles, they are affected by the aspect ratio of the plot and shown as ellipses:

cef2[{{xmin_, xmax_}, {ymin_, ymax_}}, data_, metadata_] := 
    {Black, Circle[{RandomReal[{xmin, xmax}], #}, 0.05]& /@ data};

DistributionChart[data, ChartElementFunction -> cef2]

enter image description here

Is there a way to get the scaling right, for example make the markers behave like PlotMarkers in ListPlot?

$\endgroup$
2
$\begingroup$

Use Offset to set the radius in printer points:

cef2[{{xmin_, xmax_}, {ymin_, ymax_}}, data_, metadata_] := {Black, 
   Circle[{RandomReal[{xmin, xmax}], #}, Offset[3]] & /@ data};

DistributionChart[data, ChartElementFunction -> cef2]

enter image description here

You can make the radius an argument of the chart element function:

cef2b[radius_: 3][{{xmin_, xmax_}, {ymin_, ymax_}}, data_, metadata_] := {Black, 
   Circle[{RandomReal[{xmin, xmax}], #}, Offset[radius]] & /@ data};

DistributionChart[data, ChartElementFunction -> cef2b[]]

same picture

Alternatively, you can use Inset[Graphics[Circle[]],...] to make the glyph:

cef2c[size_: .025][{{xmin_, xmax_}, {ymin_, ymax_}}, data_, metadata_] := {Black, 
   Inset[Graphics @ Circle[], {RandomReal[{xmin, xmax}], #}, Automatic, 
       Scaled[size]] & /@ data};

DistributionChart[data, ChartElementFunction -> cef2c[.05], AspectRatio -> 1/2]

enter image description here

Use ChartElementFunction -> cef2c[.1] to get

enter image description here

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Thanks so much! Exactly what I was looking for. $\endgroup$ – wigg0t Jun 21 '19 at 6:54
  • $\begingroup$ @wigg0t, my pleasure. Thank you for the accept. $\endgroup$ – kglr Jun 21 '19 at 6:55

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.