# Scale maximum width of distributions in DistributionChart proportional to sample size?

I am looking to compare three different distributions by making a chart with the three violin plots via DistributionChart. The distributions have different sample sizes, and by default each distribution has a uniform maximum width. Is it possible to scale the maximum width of each distribution by the sample size of that distribution such that the three distributions on the single chart have different maximum widths?

• Edit your question to provide a minimal working example including code and data. Jul 11, 2018 at 15:51
• Welcome! To make the most of Mma.SE start by taking the tour now. It will help us to help you if you write an excellent question. Please Edit to show your due diligence, give brief context, include minimal working example of code and data in formatted form. As you receive give back, vote and answer questions, keep the site useful, be kind, correct mistakes and share what you have learned. Jul 11, 2018 at 15:53
• Is there a reason why you wouldn't want the areas equal rather than the width being proportional to sample size? You might want to look at mathematica.stackexchange.com/questions/145810/….
– JimB
Jul 11, 2018 at 16:25

DistributionChart[data, Method -> {"BoxWidth" -> "Scaled"}]


makes the bar widths proportional to the square root of the data sizes.

The first example in DistributionChart >> Options >> Method:

data = Table[RandomReal[NormalDistribution[], i], {i, {100, 400, 900, 1600}}];
DistributionChart[data,
Method -> {"BoxWidth" -> "Scaled"},
ChartLabels -> Length /@ data]


• I would like further control over the violin chart preferably being able to control the SmoothKernelDistribution directly. In my case the problem is that the data provided is in integer form even though the underlying values are random reals. I would like the Method to allow for direct control of SmoothKernelDistribution. In my case I would like Method-> Function[x,SmoothKernelDistribution[x,1] so that the selected data is fed to this function. Oct 27, 2022 at 11:30

I know this isn't what you asked. But for a comparison among violin plots where the distribution shape and the sample size affect what you see, I'm not sure how one would interpret differences.

If you want to compare shapes of the distributions a much more direct approach is the following:

SeedRandom[12345];
data1 = RandomVariate[NormalDistribution[-1, 1], 1000];
data2 = RandomVariate[NormalDistribution[0, 3], 200];
data3 = RandomVariate[LogNormalDistribution[0, 0.6], 500];
skd1 = SmoothKernelDistribution[data1];
skd2 = SmoothKernelDistribution[data2];
skd3 = SmoothKernelDistribution[data3];
Plot[{PDF[skd1, x], PDF[skd2, x], PDF[skd3, x]},
{x, Min[data1, data2, data3], Max[data1, data2, data3]},
PlotRange -> {All, All},
PlotLegends -> {"Data 1", "Data 2", "Data 3"}]