geom_vline
and geom_abline
for other types of
lines).geom_hline(mapping = NULL, data = NULL, stat = "hline",
position = "identity", show_guide = FALSE, ...)
aes
or aes_string
. Only needs to be set
at the layer level if you are overriding the plot defaults.FALSE
)p + geom_hline(aes(yintercept=mpg)) p + geom_hline(yintercept=20) p + geom_hline(yintercept=seq(10, 30, by=5))
# With coordinate transforms p + geom_hline(aes(yintercept=mpg)) + coord_equal() p + geom_hline(aes(yintercept=mpg)) + coord_flip() p + geom_hline(aes(yintercept=mpg)) + coord_polar()
# 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)
geom_vline
for vertical lines,
geom_abline
for lines defined by a slope and intercept,
geom_segment
for a more general approach