i

R Programming Complete Tutorial

R Violin Plots

A Violin Plot is a combination of a Kernel Density Plot and a  boxplot. We can create them using the vioplot () function from vioplot packages.

Example of vioplot() Function:

In this example, we are storing the mpg data associated with cyl value equals to 4, into the variable x1. Similar to this, we are storing data related to cycle value 6 and 8 into x2 and x3, respectively. Now we are going to use the vioplot () function to create a violin plot, where it's sharing that for 4 cycle, the mpg will be in between 22 to 32. For 6 cycles it's 18 to 20, and for 8 cycles it's from 10 to 18.

Graph output: