- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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 change the linetype for geom_vline in R?
To change the linetype for geom_vline, we can use linetype argument in geom_vline function of ggplot2 package. There are mainly six linetypes that can be used and these values are 0=blank, 1=solid (default), 2=dashed, 3=dotted, 4=dotdash, 5=longdash, 6=twodash.
Consider the below data frame −
x<-rnorm(1000) df<-data.frame(x)
Loading ggplot2 package and creating histogram of x with vertical line −
Example
library(ggplot2) ggplot(df,aes(x))+geom_histogram(bins=10)+geom_vline(xintercept=0)
Output
Creating histogram of x with vertical line of different line type −
Example
ggplot(df,aes(x))+geom_histogram(bins=10)+geom_vline(xintercept=0,linetype="dotdash")
Output
Advertisements