使用ggplot在某些x轴值上添加虚线垂直线 [英] Add a dotted vertical line on certain x-axis values using ggplot

查看:8729
本文介绍了使用ggplot在某些x轴值上添加虚线垂直线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

轴的值是-6,-4,-2,0,2,4,6,在密度图中有一些y值。
是否可以使用ggplot在特定x轴值(外汇:-3和+3)上添加虚线垂直线?

 <$ (1000,0,1),y = rnorm(1000,
0,2),z = rnorm(c,c) (df.m)+ geom_freqpoly(aes(x = value,
y = ..density ..)(
df.m < - 熔体(df)
ggplot ,color = variable))


解决方案

c> geom_vline :

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


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))

解决方案

Try geom_vline:

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

这篇关于使用ggplot在某些x轴值上添加虚线垂直线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆