当x轴是一个因子时,用ggplot添加一条垂直线 [英] Add a vertical line with ggplot when x-axis is a factor
本文介绍了当x轴是一个因子时,用ggplot添加一条垂直线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码用于处理ggplot2的pre-version .9。
df = data.frame(x = letters [1:26],y = abs(rnorm (26)))
pre>
ggplot(df,aes(x = x,y = y))+ geom_bar()+ geom_vline(xintercept ='m')
我得到以下错误:
as.character(FUN),mode =function,envir = envir):未找到
$ p $我不知道(不记得)如果你的原来用于旧版本的ggplot工作,但你可以使用一个另一种方法是这样的:
模式'function'的对象'm'
$ b $ pre $ g $ pggplot(df,aes(x = x,y = y))+ geom_bar()+ geom_vline(xintercept = which(df $ x =='m'))
!
The following code use to work pre-version .9 of ggplot2. Is this not possible anymore?
df = data.frame(x = letters[1:26], y=abs(rnorm(26))) ggplot(df, aes(x=x, y=y)) + geom_bar() + geom_vline(xintercept='m')
I get the following error:
Error in get(as.character(FUN), mode = "function", envir = envir) : object 'm' of mode 'function' was not found
解决方案I don't know (don't remember) if your original used to work with old version of ggplot but you can use an another approach like this one :
ggplot(df, aes(x=x, y=y)) + geom_bar() + geom_vline(xintercept=which(df$x == 'm'))
Hope this help !!!
这篇关于当x轴是一个因子时,用ggplot添加一条垂直线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文