Violin plots in R with Highcharter

Violin plots in R with HighcharterLuís SousaBlockedUnblockFollowFollowingMay 17A known shortcoming of Highcharts.

js is the inability to make Violin plots.

Violin plots are a popular form of box plots, augmented by a two-sided visualization of the distribution of the dataset.

Here’s an example of a violin plot:()Source: http://www.


com/english/wiki/ggplot2-violin-plot-quick-start-guide-r-software-and-data-visualizationAlthough it is relatively tricky to implement this in pure JavaScript (D3.

js has this, for instance), we can when using a wrapper library like python-highcharts or Highcharter.

For the former, have a look here.

That repo was actually an inspiration for this post!In this article we’ll delve into the latter.

Preparing the dataWe’ll just take a few random numbers and pretend they represent some feature of Adam, Bart and Carl.

It is very important to haveMake sure you import both magrittr and highcharter for the code in this post to work!Preparing the density plotsThis is the heart of the solution: turning arrays of numbers into a distribution.

This can be done in using R’s built-in density() function:The ready-to-use functionOur violin plot relies heavily on the built-in chart type areasplinerange from Highcharts.

We use it for both the violin plot and the box plot in front of it!The line joining the 5% and 95% percentiles is drawn using an ordinary line plot.

NotesThe height of the box plot is controlled using the delta parameter.

The resultThis is what our violin plots look like:Unlike the ggplot2 version, this chart is hoverable, so that we can enrich it with tooltips and whatnot!.

. More details

Leave a Reply