geom_boxplot {ggplot2}R Documentation

geom\_boxplot

Description

Box and whiskers plot

Usage

geom_boxplot(mapping = NULL, data = NULL, stat = "boxplot", position = "dodge", 
    outlier.colour = "black", outlier.shape = 16, outlier.size = 2, 
    ...)

Arguments

mapping

mapping between variables and aesthetics generated by aes

data

dataset used in this layer, if not specified uses plot dataset

stat

statistic used by this layer

position

position adjustment used by this layer

outlier.colour

colour for outlying points

outlier.shape

shape of outlying points

outlier.size

size of outlying points

...

other arguments

Details

This page describes geom\_boxplot, see layer and qplot for how to create a complete plot from individual components.

Value

A layer

Aesthetics

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))

Author(s)

Hadley Wickham, http://had.co.nz/

See Also

Examples

## Not run: 
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")
qplot(year, budget, data = movies, geom = "boxplot", 
  group = round_any(year, 10, floor))


## End(Not run)

[Package ggplot2 version 0.8.9 Index]