Violin plot from summary data

by The Thunder Chimp   Last Updated January 06, 2018 20:26 PM

I'd like to use a violin plot to visualise the number of archaeological artefacts by site (A and B) and by century with data in the following format (years are Before Present):

Year SiteA SiteB
22400 356 182
22500 234 124
22600 144 231
...
24800 112  32

There are some 6000 artefacts in total. In ggplot2, it would seem as if the preferred data entry format is of one line per observation (artefact) for a violin plot:

Site Year
A    22400
A    22400
... (356 times)
A    22400
B    22400
B    22400
... (182 times)
A    22500
A    22500
... (234 times)
A    22500
... ... ... (~5000 lines)
B    24800
B    24800
... (32 times)
B    24800

Is there an effective way of converting summary dataframe (1st grey box) into an observation-by-observation dataframe (2nd grey box) for use in a violin plot?

Alternatively, is there a way of making violin plots from data formatted as in the first grey box?

The plot would look like this:

enter image description here

Tags : r ggplot2


Related Questions


R - How to find points within specific Contour

Updated May 28, 2015 23:11 PM

How to see the code of a stored plot (ggplot)

Updated May 29, 2015 01:11 AM

R ggplot remove certain items from legend

Updated April 03, 2015 23:11 PM

add second axis label

Updated April 10, 2015 23:11 PM

Error in facet_grid in ggplot2

Updated October 09, 2016 09:11 AM