geom_hline {ggplot2}R Documentation

geom\_hline

Description

Line, horizontal

Usage

geom_hline(mapping = NULL, data = NULL, stat = "hline", position = "identity", 
    ...)

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

...

ignored

Details

This geom allows you to annotate the plot with horizontal lines (see geom\_vline and geom\_abline for other types of lines)

There are two ways to use it. You can either specify the intercept of the line in the call to the geom, in which case the line will be in the same position in every panel. Alternatively, you can supply a different intercept for each panel using a data.frame. See the examples for the differences

This page describes geom\_hline, 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\_hline. Aesthetics are mapped to variables in the data with the aes function: geom\_hline(aes(x = var))

Author(s)

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

See Also

Examples

## Not run: 
p <- ggplot(mtcars, aes(x = wt, y=mpg)) + geom_point()

p + geom_hline(aes(yintercept=mpg))
p + geom_hline(yintercept=20)
p + geom_hline(yintercept=seq(10, 30, by=5))

# To display different lines in different facets, you need to 
# create a data frame.
p <- qplot(mpg, wt, data=mtcars, facets = vs ~ am)

hline.data <- data.frame(z = 1:4, vs = c(0,0,1,1), am = c(0,1,0,1))
p + geom_hline(aes(yintercept = z), hline.data)

## End(Not run)

[Package ggplot2 version 0.8.9 Index]