View source: R/geom_split_violin.R
geom_split_violin | R Documentation |
This geometry displays the density distribution of two groups side by side,
as two halves of a violin. Note that an emptyx
aesthetic has to be provided
even if you want to plot a single variable (see example below).
geom_split_violin(
mapping = NULL,
data = NULL,
stat = "ydensity",
position = "identity",
nudge = 0,
...,
draw_quantiles = NULL,
trim = TRUE,
scale = "area",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
Use to override the default connection between
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
nudge |
Add space between the half-violin and the middle of the space allotted to a given factor on the x-axis. |
... |
Other arguments passed on to
|
draw_quantiles |
If |
trim |
If |
scale |
if "area" (default), all violins have the same area (before trimming the tails). If "count", areas are scaled proportionally to the number of observations. If "width", all violins have the same maximum width. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
The implementation is based on https://stackoverflow.com/questions/35717353/split-violin-plot-with-ggplot2. Credit goes to @jan-jlx for providing a complete implementation on StackOverflow, and to Trang Q. Nguyen for adding the nudge parameter.
a ggplot2::layer
object
data("bradypus", package = "maxnet")
bradypus_tb <- tibble::as_tibble(bradypus) %>%
dplyr::mutate(presence = relevel(
factor(
dplyr::case_match(
presence, 1 ~ "presence",
0 ~ "absence"
)
),
ref = "presence"
))
ggplot(bradypus_tb, aes(
x = "",
y = cld6190_ann,
fill = presence
)) +
geom_split_violin(nudge = 0.01)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.