Any ideas on where to even begin with making a violin chart using d3? Does it exist already?
I've looked around and have figured out how to do it using ggplot2 and was hoping there'd be a ready-made example that I could learn from but haven't found one yet.
I suppose I could do a really painful process of making various size bars on top of each other, or taking a distribution, rotating it and mirroring it. But surely there's a better way.
Any ideas on where to even begin with making a violin chart using d3? Does it exist already?
I've looked around and have figured out how to do it using ggplot2 and was hoping there'd be a ready-made example that I could learn from but haven't found one yet.
I suppose I could do a really painful process of making various size bars on top of each other, or taking a distribution, rotating it and mirroring it. But surely there's a better way.
Share Improve this question edited Sep 12, 2012 at 17:48 paxRoman 2,0623 gold badges19 silver badges32 bronze badges asked Jul 25, 2012 at 14:27 ScottieBScottieB 4,0628 gold badges46 silver badges61 bronze badges 2- 2 TBH, i don't know what violin chart is :) But if you can make almost anything in D3, so if you can provide some more info on violin charts (some example would be nice) i'm sure we can find a way to help you. – kodisha Commented Jul 25, 2012 at 14:56
- en.wikipedia/wiki/Violin_plot – ScottieB Commented Aug 2, 2012 at 5:38
2 Answers
Reset to default 8I needed that for myself so here it is: violin plot
As far as I know, nobody has done this before, but it shouldn't be too hard. I would start as if I was making a line chart (or boxed instead of lines) for one half of a violin. That is, create the appropriate x and y scales and add the data in. The result of this I would rotate and translate to the correct position. Then do the same thing again and mirror it as well to get the other half of the violin.
This may sound plex, but SVG has built-in support for these operations (rotating and mirroring). You should be able to approach this pretty much like drawing a line graph of the distribution with 2-3 simple operations on top of that. Wrap everything in a function and you've got something you can call to create a violin.
It of course also depends in what form you have the data to make the plot. A line plot might not be feasible because of too few data points, but then you can easily use bars instead.