geom_hline

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

Line, horizontal

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.

What do you think of the documentation? Please let me know by filling out this short online survey.

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)). 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
colourblackbrewer, gradient, gradient2, gradientn, grey, hue, identity, manual
size0.5identity, manual, size
linetype1identity, linetype, manual
alpha1

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

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.

Returns

This function returns a layer object.

See also

Examples

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

What do you think of the documentation? Please let me know by filling out this short online survey.