A violin plot is an alternative to the more usual boxplot, especially interesting with large dataset where boxplot could hide a part of the information. Here is a simple implementation in d3.js using the d3.histogram()
function, keeping only the core code to understand the fundamental concept.
d3.histogram()
function, not using a kernel density estimate.thresholds
argument of the d3.histogram()
function. It is advised to try different bin size.padding
argument of the x axis to control space between violin.
It is important to understand that in the violin chart above the smoothing effect is due to a curve interpolation between bins. Here is the result without any interpolation (left) and using a curveStep
interpolation (right). Just change the .curve()
call in the code above to get these results.