geom_split_violin {tidysdm} | R Documentation |
Split violin geometry for ggplots
Description
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).
Usage
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
)
Arguments
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 |
Position adjustment, either as a string naming the adjustment
(e.g. |
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 |
Details
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.
Value
a ggplot2::layer
object
Examples
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)