type_violin | R Documentation |
Type function for violin plots, which are an alternative to box plots for visualizing continuous distributions (by group) in the form of mirrored densities.
type_violin(
bw = "nrd0",
joint.bw = c("mean", "full", "none"),
adjust = 1,
kernel = c("gaussian", "epanechnikov", "rectangular", "triangular", "biweight",
"cosine", "optcosine"),
n = 512,
trim = FALSE,
width = 0.9
)
bw |
the smoothing bandwidth to be used. The kernels are scaled such that this is the standard deviation of the smoothing kernel. (Note this differs from the reference books cited below.)
The specified (or computed) value of |
joint.bw |
character string indicating whether (and how) the smoothing
bandwidth should be computed from the joint data distribution when there
are multiple subgroups. The options are |
adjust |
the bandwidth used is actually |
kernel |
a character string giving the smoothing kernel to be used. This
must partially match one of
|
n |
the number of equally spaced points at which the density is
to be estimated. When |
trim |
logical indicating whether the violins should be trimmed to the
range of the data. Default is |
width |
numeric (ideally in the range |
See type_density
for more details and considerations related to
bandwidth selection and kernel types.
# "violin" type convenience string
tinyplot(count ~ spray, data = InsectSprays, type = "violin")
# aside: to match the defaults of `ggplot2::geom_violin()`, use `trim = TRUE`
# and `joint.bw = FALSE`
tinyplot(count ~ spray, data = InsectSprays, type = "violin",
trim = TRUE, joint.bw = FALSE)
# use flip = TRUE to reorient the axes
tinyplot(count ~ spray, data = InsectSprays, type = "violin", flip = TRUE)
# for flipped plots with long group labels, it's better to use a theme for
# dynamic plot resizing
tinytheme("clean")
tinyplot(weight ~ feed, data = chickwts, type = "violin", flip = TRUE)
# 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", fill = 0.2)
# note: above we relied on `...` argument passing alongside the "violin"
# type convenience string. But this won't work for `width`, since it will
# clash with the top-level `tinyplot(..., width = <width>)` arg. To ensure
# correct arg passing, it's safer to use the formal `type_violin()` option.
tinyplot(len ~ dose | supp, data = ToothGrowth, fill = 0.2,
type = type_violin(width = 0.8))
# reset theme
tinytheme()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.