stat_sum {ggplot2}R Documentation

stat_sum

Description

Sum unique values. Useful for overplotting on scatterplots

Usage

stat_sum(mapping=NULL, data=NULL, geom="point", position="identity", ...)

Arguments

mapping mapping between variables and aesthetics generated by aes
data dataset used in this layer, if not specified uses plot dataset
geom geometric used by this layer
position position adjustment used by this layer
... ignored

Details

This page describes stat_sum, 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 stat_sum. Aesthetics are mapped to variables in the data with the aes function: stat\_sum(\code{aes}(x = var))

Author(s)

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

See Also

Examples

## Not run: 
d <- ggplot(diamonds, aes(x = cut, y = clarity))
# Need to control which group proportion calculated over
# Overall proportion
d + stat_sum(aes(group = 1))
d + stat_sum(aes(group = 1)) + scale_size(to = c(3, 10))
d + stat_sum(aes(group = 1)) + scale_area(to = c(3, 10))
# by cut
d + stat_sum(aes(group = cut))
d + stat_sum(aes(group = clarity, colour = cut))
# by clarity
d + stat_sum(aes(group = clarity))
d + stat_sum(aes(group = clarity, colour = clarity))

# Instead of proportions, can also use sums
d + stat_sum(aes(size = ..n..))

# Can also weight by another variable
d + stat_sum(aes(group = 1, weight = price))
d + stat_sum(aes(group = 1, weight = price, size = ..n..))

# Or using qplot
qplot(cut, clarity, data = diamonds)
qplot(cut, clarity, data = diamonds, stat = "sum", group = 1)    
## End(Not run)

[Package ggplot2 version 0.8.2 Index]