Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
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
