O'Reilly logo

R Data Visualization Cookbook by Atmajitsinh Gohil

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generating a violin plot

Violin plots are very similar to box plots. It is hard to glorify one over the other. I observe that box plots look a little more cluttered when they are plotted along with outliers.

In the following violin plot, we can observe the mean, which is displayed using white dots, and the dispersion of various variables:

Generating a violin plot

Getting ready

We need to install and load the ISLR and vioplot packages using the following lines of code:

install.packages(c("ISLR","vioplot"))
library(ISLR)
library(vioplot)

We require the ISLR package to download the baseball dataset in R. The vioplot package is utilized to generate the violin plot.

How to do it… ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required