# "violin" type convenience string
tinyplot(weight ~ feed, data = chickwts, type = "violin")
# to match the defaults of `ggplot2::geom_violin()`, use `trim = TRUE` and
# `joint.bw = FALSE`
tinyplot(
weight ~ feed, data = chickwts,
# type = type_violin(trim = TRUE, joint.bw = FALSE) # same but see final ex.
type = "violin", trim = TRUE, joint.bw = FALSE
)
# For flipped violin plots, it's usually better to use a dynamic theme to
# accommodate (horizontal) y-axis labels
tinyplot(
weight ~ feed, data = chickwts, type = "violin", flip = TRUE,
theme = "dynamic" # or "clean(2)", "classic", "minimal", etc.
)
# you can group by the x var to add colour (here with the original orientation)
tinyplot(weight ~ feed | feed, data = chickwts, type = "violin", legend = FALSE)
# dodged grouped violin plot example (different dataset)
tinyplot(len ~ dose | supp, data = ToothGrowth, type = "violin")
# the "sina" type shows the observations themselves, rather than a smooth
# outline drawn around them
tinyplot(weight ~ feed, data = chickwts, type = "sina")
# layering a sina on top of a violin lines up exactly, since the points are
# displaced by the violin's own half-width
tinyplot(weight ~ feed, data = chickwts, type = "violin")
tinyplot_add(type = "sina", pch = 16, col = "black")
# unlike `type_violin()`, `type_sina()` supports a continuous `by` variable;
# it colours the points rather than splitting them into groups
tinyplot(
Sepal.Length ~ Species | Petal.Width, data = iris,
type = "sina", pch = 16
)
# note: above we relied on `...` argument passing alongside the type
# convenience strings. But this won't work for `width`, since it will
# clash with the top-level `tinyplot(..., width = )` arg. To ensure
# correct arg passing, it's safer to use the functional type.
tinyplot(
len ~ dose | supp, data = ToothGrowth,
type = type_violin(width = 0.75)
)
Run the code above in your browser using DataLab