- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to draw a violin plot in R?
A violin plot is similar to a boxplot but looks like a violin and shows the distribution of the data for different categories. It shows the density of the data values at different points. In R, we can draw a violin plot with the help of ggplot2 package as it has a function called geom_violin for this purpose.
Consider the below data frame −
set.seed(1) x <-rep(c("S1","S2","S3","S4","S5"),each=50) set.seed(1) x <-rep(c("S1","S2","S3","S4","S5"),each=100) y <-rnorm(500) grp <-rep(c("A","B"),times=250) df <-data.frame(x,y,grp) head(df,20)
x y grp 1 S1 -0.62645381 A 2 S1 0.18364332 B 3 S1 -0.83562861 A 4 S1 1.59528080 B 5 S1 0.32950777 A 6 S1 -0.82046838 B 7 S1 0.48742905 A 8 S1 0.73832471 B 9 S1 0.57578135 A 10 S1 -0.30538839 B 11 S1 1.51178117 A 12 S1 0.38984324 B 13 S1 -0.62124058 A 14 S1 -2.21469989 B 15 S1 1.12493092 A 16 S1 -0.04493361 B 17 S1 -0.01619026 A 18 S1 0.94383621 B 19 S1 0.82122120 A 20 S1 0.59390132 B
Creating violin plot by filling colors with x variable −
Creating violin plot by filling colors with grp variable −
- How can every violin in a violin plot be split in Python Seaborn Library?
- How to create violin plot for categories with grey color palette using ggplot2 in R?
- Python Pandas - Draw a violin plot and set quartiles as horizontal lines with Seaborn
- Python Pandas - Draw swarms of observations on top of a violin plot with Seaborn
- Python Pandas - Draw a violin plot, explicit order and show observation as a stick with Seaborn
- How to create violin plot for categories with grey color palette in reverse order using ggplot2 in R?
- How to plot two violin plot series on the same graph using Seaborn?
- Python Pandas - Draw a violin plot and control order by passing an explicit order with Seaborn
- Create a Violin Plot with SeaBorn – Python Pandas
- Explain how a violin plot can be visualized using factorplot function in Python?
- How to plot a function in R?
- How to draw a circle in R?
- How to draw axis lines inside a plot in Matplotlib?
- How to create a staircase plot in R?
- How to create a plot in R with gridlines using plot function?