- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create dotted vertical lines in a plot using ggplot2 in R?
In any plot, the vertical lines are generally used to show the thresholds for something, for example, range of the variable under consideration. The package ggplot2 provides geom_vline function to create vertical lines on a plot and we have linetype argument of this function which can be used to draw dotted vertical lines.
Example
Consider the below data frame −
set.seed(9) x <-rnorm(100,0.5) df <-data.frame(x)
Creating histogram of x with dotted vertical lines −
Example
library(ggplot2) ggplot(df,aes(x))+geom_histogram(bins=15)+geom_vline(xintercept=c(-2,2),linetype="dotted")
Output
Example
ggplot(df,aes(x))+geom_histogram(bins=15)+geom_vline(xintercept=c(-3,3),linetype="dotted")
Output
- Related Articles
- How to create a dotted vertical line using ggplot2 in R?
- How to create a stacked bar plot with vertical bars in R using ggplot2?
- Create multiple regression lines in a single plot using ggplot2 in R.
- How to create two vertical lines on a plot with shaded area in-between using R?
- How to create a dot plot using ggplot2 in R?
- How to create quantile regression plot with larger width of lines using ggplot2 in R?
- How to create facets in vertical order using ggplot2 in R?
- How to create multiple regression lines using ggplot2 in R?
- How to create transparent bar plot using ggplot2 in R?
- How to create an empty plot using ggplot2 in R?
- How to create two plots using ggplot2 arranged in a vertical manner in R?
- How to create a bar plot with ggplot2 using stat_summary in R?
- How to create a line chart using ggplot2 with a vertical line in R?
- How to create a circle with vertical lines in R?
- How to create stacked plot with density using ggplot2 in R?

Advertisements