English 中文(简体)
在X-轴心是个因素时添加一条垂直线。
原标题:Add a vertical line with ggplot when x-axis is a factor
  • 时间:2012-04-19 21:14:49
  •  标签:
  • r
  • ggplot2

下述法典用于编前第9版。 难道这是不可能的吗?

df = data.frame(x = letters[1:26], y=abs(rnorm(26)))
ggplot(df, aes(x=x, y=y)) + geom_bar() + geom_vline(xintercept= m )

我有以下错误:

Error in get(as.character(FUN), mode = "function", envir = envir) : object m of mode function was not found

最佳回答

我不知道(don)您的原件是否用于处理老版的愤怒,但你可以采用另一种做法,如:

ggplot(df, aes(x=x, y=y)) + geom_bar() + geom_vline(xintercept=which(df$x ==  m ))

希望这一帮助!

问题回答

答案是为那些希望在分类的X-轴体中增加垂直线的人进行的更为广泛的讨论。

我有5个群体和5个因素。 我想在每一组的最后一项因素后面加上4条垂直线,以分离这5个群体(在E类情况下)。 @dickoa的方法对我的案件没有作用。 当我使用时:

geom_vline(xintercept=which(df$x ==  m ))

It only adds vertical line at m of the 3rd group. I just find that I can try sth like this:

geom_vline(xintercept = c(1.5,2.5,3.5,4.5))

这至少对我的案件是完美的。 也许你需要几次努力,找到适合你情况的模式。

我总是想知道,如何根据x/y轴心的比例增加垂直/横向线。 例如,xintercept =0.5 系指在轴心中间添加垂直线,Xintercept = 0.25 表示第一季度。 然而,我无法了解这个问题。





相关问题
How to plot fitted model over observed time series

This is a really really simple question to which I seem to be entirely unable to get a solution. I would like to do a scatter plot of an observed time series in R, and over this I want to plot the ...

REvolution for R

since the latest Ubuntu release (karmic koala), I noticed that the internal R package advertises on start-up the REvolution package. It seems to be a library collection for high-performance matrix ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Changing the order of dodged bars in ggplot2 barplot

I have a dataframe df.all and I m plotting it in a bar plot with ggplot2 using the code below. I d like to make it so that the order of the dodged bars is flipped. That is, so that the bars labeled "...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Generating non-duplicate combination pairs in R

Sorry for the non-descriptive title but I don t know whether there s a word for what I m trying to achieve. Let s assume that I have a list of names of different classes like c( 1 , 2 , 3 , 4 ) ...

Per panel smoothing in ggplot2

I m plotting a group of curves, using facet in ggplot2. I d like to have a smoother applied to plots where there are enough points to smooth, but not on plots with very few points. In particular I d ...

热门标签