The ggviolinbox package extends ggplot2 by providing custom geoms for creating half-violin plots, half-boxplots, and combinations of both. These functions are useful for visualizing distributions and comparisons in a compact and elegant way.
You can install the ggviolinbox package from GitHub using the devtools package:
if(!require(devtools)) install.packages("devtools")
devtools::install_github("dsmutin/ggviolinbox")The package provides the following functions:
geom_halfviolin(): Creates a half-violin plot (mirrored density plot).geom_halfboxplot(): Creates a half-boxplot (mirrored boxplot).geom_violinboxplot(): Combines a half-violin and a half-boxplot into a single plot.ggviolinbox(): A convenience wrapper forgeom_violinbox().
Creates a half-violin plot. Use the panel parameter to specify which side to display.
library(ggplot2)
library(ggviolinbox)
ggplot(mpg, aes(class, hwy)) +
geom_halfviolin(panel = "right") +
theme_minimal()Creates a half-boxplot. Use the panel parameter to specify which side to display.
ggplot(mpg, aes(class, hwy)) +
geom_halfboxplot(panel = "left") +
theme_minimal()Combines a half-violin and a half-boxplot. Use the boxplot and violinplot parameters to specify which side each geom appears on.
ggplot(mpg, aes(class, hwy)) +
geom_violinboxplot(boxplot = "left", violinplot = "right") +
theme_minimal()A convenience wrapper for geom_violinbox().
ggviolinbox(boxplot = "left", violinplot = "right") +
theme_minimal()ggplot(mpg, aes(class, hwy)) +
geom_halfviolin(panel = "right", fill = "skyblue") +
labs(title = "Half-Violin Plot", x = "Class", y = "Highway MPG") +
theme_minimal()ggplot(mpg, aes(class, hwy)) +
geom_halfboxplot(panel = "left", fill = "lightgreen") +
labs(title = "Half-Boxplot", x = "Class", y = "Highway MPG") +
theme_minimal()ggplot(mpg, aes(class, hwy)) +
geom_violinboxplot(boxplot = "left", violinplot = "right",
box_fill = "lightgreen", violin_fill = "skyblue") +
labs(title = "Violin-Boxplot Combination", x = "Class", y = "Highway MPG") +
theme_minimal()panel: Specifies which side to display ("left"or"right").- All other parameters are inherited from
ggplot2::geom_violin().
panel: Specifies which side to display ("left"or"right").- All other parameters are inherited from
ggplot2::geom_boxplot().
boxplot: Specifies which side the boxplot appears on ("left"or"right").violinplot: Specifies which side the violin plot appears on ("left"or"right").- All other parameters are inherited from
ggplot2::geom_violin()andggplot2::geom_boxplot().
- Same parameters as
geom_violinboxplot().
Contributions are welcome! If you find a bug or have a feature request, please open an issue on GitHub. If you'd like to contribute code, fork the repository and submit a pull request.
This package is licensed under the MIT License. See the LICENSE file for details.
- Inspired by the
ggridges,ggExtraandggplot2packages. - Many thanks to the
introindatavizpackage for previous implementations.
For questions or feedback, please contact D. Smutin at dvsmutin@gmail.com.


