- Related Questions & Answers
- How to create a line chart using ggplot2 with larger width in R?
- How to create line chart using ggplot2 in R with 3-sigma limits?
- How to create a line chart with mean and standard deviation using ggplot2 in R?
- How to create a line chart for a subset of a data frame using ggplot2 in R?
- How to create a vertical line with CSS?
- How to create a line chart using JavaFX?
- How to create a line chart in R using plot function with larger width?
- How to change the color of lines for a line chart using ggplot2 in R?
- How to add a vertical line with some value on a scatterplot created by ggplot2 in R?
- How to create a Matplotlib bar chart with a threshold line?
- How to create bar chart using ggplot2 with chart sub-title in R?
- How to create a point chart with empty points using ggplot2 in R?
- How to create multiple lines chart with unique line types in R?
- How to create regression model line in a scatterplot created by using ggplot2 in R?
- How to create a stacked bar plot with vertical bars in R using ggplot2?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In general, the line chart is drawn to view the trend of something and we might also have some threshold point for that trend, for example, if blood pressure is plotted then we might want to show 60 mm Hg as well because this is the lowest acceptable value for blood pressure recommended by doctors. Therefore, it can be plotted as a vertical line if we want to plot blood pressures of a person. Similarly, there can be many situations where we can use a vertical line to visualize the threshold value. This can be achieved in ggplot2 with the help of geom_vline function.

Consider the below data frame −

set.seed(10) x<-c(5,10,15,20,25) frequency<-c(1,12,8,16,22) df<-data.frame(x,frequency) df

x frequency 1 5 1 2 10 12 3 15 8 4 20 16 5 25 22 library(ggplot2)

Creating a simple line chart −

ggplot(df,aes(x,frequency,group=1))+geom_line()

Creating the chart with a vertical line on it −

ggplot(df,aes(x,frequency,group=1))+geom_line()+geom_vline(xintercept=8)

Advertisements