# geom_vline

0th

Percentile

##### Line, vertical.

This geom allows you to annotate the plot with vertical lines (see geom_hline and geom_abline for other types of lines.

##### Usage
geom_vline(mapping = NULL, data = NULL, stat = "vline",
position = "identity", show_guide = FALSE, ...)
##### Arguments
show_guide
should a legend be drawn? (defaults to FALSE)
mapping
The aesthetic mapping, usually constructed with aes or aes_string. Only needs to be set at the layer level if you are overriding the plot defaults.
data
A layer specific dataset - only needed if you want to override the plot defaults.
stat
The statistical transformation to use on the data for this layer.
position
The position adjustment to use for overlappling points on this layer
...
other arguments passed on to layer. This can include aesthetics whose values you want to set, not map. See layer for more details.
##### Details

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.

##### Aesthetics

[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "vline")} # 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", linetype = "longdash") p + geom_vline(aes(xintercept = wt))

# With coordinate transforms p + geom_vline(aes(xintercept = wt)) + coord_equal() p + geom_vline(aes(xintercept = wt)) + coord_flip() p + geom_vline(aes(xintercept = wt)) + coord_polar()

p2 <- p + aes(colour = factor(cyl)) p2 + geom_vline(xintercept = 15)

# To display different lines in different facets, you need to # create a data frame. p <- qplot(mpg, wt, data=mtcars, facets = vs ~ am) vline.data <- data.frame(z = c(15, 20, 25, 30), vs = c(0, 0, 1, 1), am = c(0, 1, 0, 1)) p + geom_vline(aes(xintercept = z), vline.data)

geom_hline for horizontal lines, geom_abline for lines defined by a slope and intercept, geom_segment for a more general approach"

##### Aliases
• geom_vline
Documentation reproduced from package ggplot2, version 0.9.3.1, License: GPL-2

### Community examples

viraj.rathod@utah.edu at Mar 21, 2020 ggplot2 v0.9.1

# Set up empty data frame  {r} n <- 1000 sim_frame <- data.frame(months = 1:n, fixed_costs = 3995, meals_sold = NA, price_per_meal = NA, profit_per_meal = NA, labor_costs = NA, profit = NA) head(sim_frame)  # Fill in data frame with simulated values  {r} set.seed(123) sim <- sim_frame %>% mutate(meals_sold = rnorm(n = n, mean = 3000, sd = 1000), price_per_meal = sample(x = c(20, 18.50, 16.50, 15), size = n, replace = T, prob = c(.25, .35, .3, .1)), profit_per_meal = price_per_meal - 11, labor_costs = runif(n = n, min = 5000, max = 7000), profit = meals_sold * profit_per_meal - labor_costs - fixed_costs) head(sim)  # Visualize distribution of profit  {r} ggplot(sim, aes(profit)) + geom_density() + geom_vline(xintercept = 5000, col = 2) + geom_vline(xintercept = 0, col = 2, lty = 2) + theme_minimal()+ labs(title = "Distribution of profit")