geom_boxplotgeom_boxplot(mapping=NULL, data=NULL, stat="boxplot", position="dodge", outlier.colour="black", outlier.shape=16, outlier.size=2, ...)
Box and whiskers plot
This page describes geom_boxplot, see layer and qplot for how to create a complete plot from individual components.
What do you think of the documentation? Please let me know by filling out this short online survey.
The following aesthetics can be used with geom_boxplot. Aesthetics are mapped to variables in the data with the aes function: geom_boxplot(aes(x = var)). Note that you do not need quotes around the variable name.
Scales control how the variable is mapped to the aesthetic and are listed after each aesthetic.
| Aesthetic | Default | Related scales |
|---|---|---|
| x | required | continuous, date, datetime, discrete |
| lower | required | |
| upper | required | |
| middle | required | |
| ymin | required | |
| ymax | required | |
| weight | 1 | |
| colour | grey20 | brewer, gradient, gradient2, gradientn, grey, hue, identity, manual |
| fill | white | brewer, gradient, gradient2, gradientn, grey, hue, identity, manual |
| size | 0.5 | identity, manual, size |
| alpha | 1 |
Layers are divided into groups by the group aesthetic. By default this is set to the interaction of all categorical variables present in the plot.
Parameters control the appearance of the geom. In addition to the parameters listed below (if any), any aesthetic can be used as a parameter, in which case it will override any aesthetic mapping.
outlier.colour: colour for outlying pointsoutlier.shape: shape of outlying pointsoutlier.size: size of outlying pointsThis function returns a layer object.
> p <- ggplot(mtcars, aes(factor(cyl), mpg)) > > p + geom_boxplot()> qplot(factor(cyl), mpg, data = mtcars, geom = "boxplot")
> > p + geom_boxplot() + geom_jitter()
> p + geom_boxplot() + coord_flip()
> qplot(factor(cyl), mpg, data = mtcars, geom = "boxplot") + + coord_flip()
> > p + geom_boxplot(outlier.colour = "green", outlier.size = 3)
> > # Add aesthetic mappings > # Note that boxplots are automatically dodged when any aesthetic is > # a factor > p + geom_boxplot(aes(fill = cyl))
> p + geom_boxplot(aes(fill = factor(cyl)))
> p + geom_boxplot(aes(fill = factor(vs)))
> p + geom_boxplot(aes(fill = factor(am)))
> > # Set aesthetics to fixed value > p + geom_boxplot(fill="grey80", colour="#3366FF")
> qplot(factor(cyl), mpg, data = mtcars, geom = "boxplot", + colour = I("#3366FF"))
> > # Scales vs. coordinate transforms ------- > # Scale transformations occur before the boxplot statistics are computed. > # Coordinate transformations occur afterwards. Observe the effect on the > # number of outliers. > m <- ggplot(movies, aes(y = votes, x = rating, + group = round_any(rating, 0.5))) > m + geom_boxplot()
> m + geom_boxplot() + scale_y_log10()
> m + geom_boxplot() + coord_trans(y = "log10")
> m + geom_boxplot() + scale_y_log10() + coord_trans(y = "log10")
> > # Boxplots with continuous x: > # Use the group aesthetic to group observations in boxplots > qplot(year, budget, data = movies, geom = "boxplot") Warning: Removed 53573 rows containing missing values (stat_boxplot).
> qplot(year, budget, data = movies, geom = "boxplot", + group = round_any(year, 10, floor)) Warning: Removed 53573 rows containing missing values (stat_boxplot).
![]()
What do you think of the documentation? Please let me know by filling out this short online survey.