layer_boxplots {ggvis} | R Documentation |
Display data with a boxplot.
Description
This will add boxplots to a plot. The action of layer_boxplots
depends
on whether the x
prop is continuous or categorical.
Usage
layer_boxplots(vis, ..., coef = 1.5, width = NULL)
Arguments
vis |
Visualisation to modify |
... |
Visual properties used to override defaults. |
coef |
The maximum length of the whiskers as multiple of the inter-quartile range. Default value is 1.5. |
width |
Width of each bar. When x is continuous, this controls the width in the same units as x. When x is categorical, this controls the width as a proportion of the spacing between items (default is 0.9). |
Details
The upper and lower "hinges" correspond to the first and third quartiles (the
25th and 75th percentiles). This differs slightly from the method used by the
boxplot
function, and may be apparent with small samples. See
boxplot.stats
for more information on how hinge positions are
calculated for boxplot
.
The upper whisker extends from the hinge to the highest value that is within 1.5 * IQR of the hinge, where IQR is the inter-quartile range, or distance between the first and third quartiles. The lower whisker extends from the hinge to the lowest value within 1.5 * IQR of the hinge. Data beyond the end of the whiskers are outliers and plotted as points (as specified by Tukey).
See Also
compute_boxplot
for more information on how data is
transformed.
Examples
library(dplyr)
mtcars %>% ggvis(~factor(cyl), ~mpg) %>% layer_boxplots()
# Set the width of the boxes to half the space between tick marks
mtcars %>% ggvis(~factor(cyl), ~mpg) %>% layer_boxplots(width = 0.5)
# Continuous x: boxes fill width between data values
mtcars %>% ggvis(~cyl, ~mpg) %>% layer_boxplots()
# Setting width=0.5 makes it 0.5 wide in the data space, which is 1/4 of the
# distance between data values in this particular case.
mtcars %>% ggvis(~cyl, ~mpg) %>% layer_boxplots(width = 0.5)
# Smaller outlier points
mtcars %>% ggvis(~factor(cyl), ~mpg) %>% layer_boxplots(size := 20)