Add a dotted vertical line on certain x-axis values using ggplot

RGgplot2

R Problem Overview


axis values are -6,-4,-2, 0, 2,4, 6 with some y values in a density plot. Is it possible to Add dotted vertical lines on certain x-axis values (Forex: -3 and +3 )using ggplot ?

library(ggplot2)
df <- data.frame(x = rnorm(1000, 0, 1), y = rnorm(1000,
     0, 2), z = rnorm(1000, 2, 1.5))
df.m <- melt(df)
ggplot(df.m) + geom_freqpoly(aes(x = value,
     y = ..density.., colour = variable))

R Solutions


Solution 1 - R

Try geom_vline:

ggplot(df.m) +
  geom_freqpoly(aes(x=value, y=..density.., colour=variable)) +
  geom_vline(xintercept=c(-3,3), linetype="dotted")

geom_vline example

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrepinementerView Question on Stackoverflow
Solution 1 - RrcsView Answer on Stackoverflow