# How can I place DistributionChart at desired x values?

Consider a simple DistributionChart such as the following:

SeedRandom[1];
data = Table[RandomVariate[NormalDistribution[RandomInteger[5], 1], 100], {3}];
DistributionChart[data]


I want to center those three violins at desired x values on an actual x-axis (not just label them using ChartLabels), for example at x = {1.1, 2.5, 4.0}. The resulting horizontal spacing between the violins will depend on the x list and I should be able to Show the resulting plot overlaid with a regular Plot, ListPlot, etc. How can I do this?

SeedRandom[1];
data = Table[
RandomVariate[NormalDistribution[RandomInteger[5], 1], 100], {3}];


A bit hacky, but these polygons are generated and translated to positions {1.,0.},{2.,0.} and {3.,0.} respectively. This can be changed by finding the positions where these translations are happening.

Starting with chart p2, locate where the GeometricTransformation is happening and append the {2,2} which is the x translation component:

p2 = DistributionChart[data]

pos = Join[#, {2, 2}] & /@ Position[p2, GeometricTransformation[_, _]]

xpos = {1.1, 2.5, 4.0};
xtx = {#, 0} & /@ xpos;


Change the translation:

Table[Part[p2, Sequence @@ pos[[i]]] = xtx[[i]], {i, Length@pos}]


Now, superimpose on p1 which is a sin curve for reference.

p1 = Plot[Sin[x], {x, 0, 2 \[Pi]}, PlotRange -> All];

Show[p1, p2]


• This works nicely. Thank you!
– FNia
Sep 29, 2022 at 7:14
• You are welcome. Thanks for the accept.
– Syed
Sep 29, 2022 at 7:22