63

The 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))
micstr
  • 5,080
  • 8
  • 48
  • 76
repinementer
  • 723
  • 3
  • 8
  • 11

1 Answers1

119

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

rcs
  • 67,191
  • 22
  • 172
  • 153