I would also like to share my humble contribution to this post.
I have been working for quite some time already on a similar plot that I called a craviola plot (in reference to the asymmetrical "Giannini Craviola" guitar).
So a craviola plot is in essence a splitted violin plot.
By default, it looks like this:
Distributions are shown by the splitted violins. They are accompanied by boxplots, 1 box per distribution. And by a red dot symbolizing the mean of each distribution (to be clear, red dots do not always superimpose with the median line of boxplots, it just happen to be the case in my example).
This function is part of my visualization package BiocompR which you can conveniently install from the following Github repository: https://github.com/YoannPa/BiocompR
To install the package in R do: devtools::install_github("YoannPa/BiocompR")
In order to generate such plot you must use the ggcraviola()
function.
The documentation I wrote for the ggcraviola()
function already provide some examples that you can run yourself in RStudio to see its full potential:
library(BiocompR)
?ggcraviola
To reproduce the plot above you can run the following code:
library(BiocompR)
df.complete = data.frame(
Groups = rep(c('A', 'B', 'C'), each = 2000),
Conditions = rep(c('I', 'J'), each = 1000,3),
Values = c(rnorm(1000, 0), rnorm(1000, 0.5),
rnorm(1000, 3), rnorm(1000, 3.5),
rnorm(1000, -3), rnorm(1000, -3.5)))
ggcraviola(data = df.complete, lines.col = "black")
Of course you have the freedom to show/hide the boxplots and the mean (red dots) for all distributions.
ggcraviola()
works with ggplot2, so you can also add more component of customization after using the ggcraviola()
function like this:
library(BiocompR)
df.complete = data.frame(
Groups = rep(c('A', 'B', 'C'), each = 2000),
Conditions = rep(c('I', 'J'), each = 1000,3),
Values = c(rnorm(1000, 0), rnorm(1000, 0.5),
rnorm(1000, 3), rnorm(1000, 3.5),
rnorm(1000, -3), rnorm(1000, -3.5)))
ggcraviola(data = df.complete, lines.col = "black") +
ggtitle("This is a Craviola plot!") + # Add title
theme(plot.title = element_text(hjust = 0.5),
axis.text = element_text(size = 14, color = "black"),# Custom axis text
axis.title = element_text(size = 15),
legend.title = element_text(size = 13), # Change legend font size
legend.text = element_text(size = 12),
panel.background = element_blank(), # Change panel appearance
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.major.y = element_line(color = "grey"),
panel.grid.minor.y = element_line(color = "grey")) +
scale_y_continuous(expand = c(0, 0)) + #Expand fully plot panel on Y-axis
scale_fill_manual(
labels = c("Control", "Case"), # Rename conditions
values = biopalette(name = "BiocompR_cond3", mute = TRUE))
Which gives:
Hopefully someone will find the ggcraviola() function useful!
Knowing how related this topic is to the ggcraviola() function, I decided to reference it in the documentation of my package.