开发者

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

开发者 https://www.devze.com 2023-02-26 18:43 出处:网络
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?

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(1开发者_开发百科000, 2, 1.5))
df.m <- melt(df)
ggplot(df.m) + geom_freqpoly(aes(x = value,
     y = ..density.., colour = variable))


Try geom_vline:

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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消