How to make a violin plot with points marked?

I have some results from a previous computation, and I am interested in making a violin plot with the results. However, I am having some issues with the output. This is a simple code example:

p={0.00583547, 0.913935, 0.00064845, 0.0283075, 0.242314, 0.00292315,
0.313267, 0.0048271, 0., 0.0189791, 0.440537, 0.644471, 0.174219,
0.331852, 0.454559, 0.492714, 0.567449, 0.534182, 0.,
0.0396246, 0.000269544, 0.0526237, 0.507224, 0.0324656, 0.146723,
0.756949, 0.48481, 0.378945, 0.0029072, 0.00223941, 0., 0.0246697,
0.00867912, 0.00534172, 0.311157, 0.360063, 0.0276792, 
 9.43658*10^-8, 0.0192023, 0.297876, 0.603116, 0.0224907, 0.0795396,
0.0899822, 0.000250232, 0., 0.00318889, 0.0245693, 0.372268,
0.00482709};

DistributionChart[p, PerformanceGoal -> "Quality", 
     PlotTheme -> "Scientific"]

I haven’t found a way to plot the point values over the violin. In addition, all values are in the range [0,1], while due to smoothing, the violin exceeds these values.

Anyone knows how could I improve this plot in Mathematica?

Thanks in advance for any help!

Hi David,

A violin plot is usually good for comparing distributions. For a single set of values maybe a histogram would be better. Don’t know what the data represents so hard to advise.

This plots points randomly sampled from the density, not the actual points, so it will change every time it is evaluated

DistributionChart[p,
 PerformanceGoal -> "Quality", 
 PlotTheme -> "Scientific",
 ChartElementFunction -> "PointDensity"]

This restricts the plot range and uses Epilog to plot the actual values.

DistributionChart[p,
 PerformanceGoal -> "Quality", 
 PlotTheme -> "Scientific",
 PlotRange -> {0.05, 1},
 PlotRangeClipping -> True,
 Epilog -> Point[Thread[{1, p}]]]

Thanks Rohit!

I have several distributions to compare, and I think the second solution you showed looks really like what I wanted. I will just introduce some noise, so the points look a bit more wide.

Thanks again for the reply

Thank you, Rohit.

If I have more than one list, how do I plot them with different color?

list1 = RandomInteger[5, 20]

list2 = RandomInteger[11, 20]

DistributionChart[{list1, list2}, PerformanceGoal -> "Quality", 
 PlotTheme -> "Scientific", PlotRange -> {0.05, 15}, 
 PlotRangeClipping -> True, Epilog -> Point[Thread[{1, list1}]]]

Hi Mohammad,

Use ChartStyle

styles = {"Pastel", {Red, Green}, {EdgeForm[{Dashed, Thick}], {Yellow, Magenta}}};
epilog = {Point[Thread[{1, list1}]], Point[Thread[{2, list2}]]};

DistributionChart[{list1, list2},
    PerformanceGoal -> "Quality",
    PlotTheme -> "Scientific",
    PlotRange -> {0.05, 15},
    PlotRangeClipping -> True,
    ChartStyle -> #,
    Epilog -> epilog] & /@ styles //
 GraphicsRow

Thank you so much, Rohit.