geom_vline {ggplot2} | R Documentation |
Line, vertical
geom_vline(mapping=NULL, data=NULL, stat="vline", position="identity", ...)
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 |
This geom allows you to annotate the plot with vertical lines (see geom_hline 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_vline, see layer
and qplot
for how to create a complete plot from individual components.
A layer
The following aesthetics can be used with geom_vline. Aesthetics are mapped to variables in the data with the aes
function: geom\_vline(\code{aes}(x = var))
colour
: border colour
size
: size
linetype
: line type
Hadley Wickham, http://had.co.nz/
geom_hline
: for horizontal lines
geom_abline
: for lines defined by a slope and intercept
geom_segment
: for a more general approach
## Not run: # Fixed lines p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() p + geom_vline(xintercept = 5) p + geom_vline(xintercept = 1:5) p + geom_vline(xintercept = 1:5, colour="green") p + geom_vline(xintercept = "mean", size=2, colour = alpha("red", 0.2)) last_plot() + coord_equal() last_plot() + coord_flip() # Lines from data p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() p + geom_vline(xintercept = "mean") + facet_grid(. ~ cyl) p + geom_vline(aes(colour = factor(cyl)), xintercept = "mean") ## End(Not run)