- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
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 create violin plot for categories with grey color palette in reverse order using ggplot2 in R?
To create violin plot for categories with grey color palette in reverse order using ggplot2, we can follow the below steps −
- First of all, create a data frame.
- Then, create the violin plot for categories with color of violins in grey palette.
- Create the violin plot for categories with color of violins with grey palette in reverse order.
Create the data frame
Let's create a data frame as shown below −
Group<-sample(c("First","Second","Third"),25,replace=TRUE) Score<-rpois(25,10) df<-data.frame(Group,Score) df
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
Group Score 1 Second 10 2 Second 8 3 Second 7 4 Third 11 5 First 3 6 Second 13 7 Third 15 8 Third 7 9 Second 10 10 Second 8 11 Third 13 12 Third 10 13 First 8 14 Third 8 15 Second 14 16 First 9 17 Third 13 18 Second 10 19 First 9 20 Second 8 21 First 11 22 First 8 23 Third 5 24 Third 12 25 Third 11
Create violin plot with violins in grey color palette
Use scale_fill_grey to create the violin plot with violins in grey color palette −
Group<-sample(c("First","Second","Third"),25,replace=TRUE) Score<-rpois(25,10) df<-data.frame(Group,Score) library(ggplot2) ggplot(df,aes(Group,Score,fill=Group))+geom_violin()+scale_fill_grey()
Output
Create violin plot with violins in grey color palette in reverse order
Use scale_fill_grey to create the violin plot with violins in reverse order with grey color palette(the default value for start and end are start=0.2 and end=0.8) −
Group<-sample(c("First","Second","Third"),25,replace=TRUE) Score<-rpois(25,10) df<-data.frame(Group,Score) library(ggplot2) ggplot(df,aes(Group,Score,fill=Group))+geom_violin()+scale_fill_grey(start=0.8,end=0. 2)
Output
- Related Articles
- How to create violin plot for categories with grey color palette using ggplot2 in R?
- How to create boxplot for categories with grey color palette in reverse order using ggplot2 in R?
- How to create scatterplot for categories with grey color palette using ggplot2 in R?
- How to create boxplot for categories with grey color palette using ggplot2 in R?
- How to create line chart for categories with grey color palette using ggplot2 in R?
- How to create a bar plot in R filled with color palette in RColorBrewer package?
- How to create density plot for categories in R?
- How to create scatterplot using ggplot2 without grey background in R?
- Remove grey color from legend display using ggplot2 in R.
- How to create stacked plot with density using ggplot2 in R?
- How to create density plot for categories filled with different colors in R?
- How to create multiple bar plots for varying categories with same width bars using ggplot2 in R?
- How to create a bar plot with ggplot2 using stat_summary in R?
- How to create bar plot with log values using ggplot2 in R?
- How to create the bar chart with ggplot2 using color brewer in R?

Advertisements