James D Forester
2007-Oct-03 17:12 UTC
[R] ggplot2: problem with geom_errorbar and geom_abline
Hi all, I have run into what appears to be a bug in ggplot2; however, I am new to the ggplot syntax, so I might be missing a key element. The main issue is that I cannot get geom_abline to plot when colour is used to identify "group" in the main plot. When I remove colour, geom_abline works but the error bars have an undesirable line drawn between the left edges of the caps. Does anyone know how to change this behavior? I am using R version 2.5.1 and ggplot2 version 0.5.5 on Ubuntu Feisty. Thanks for your help. James ## I am using an example from http://had.co.nz/ggplot2/geom_errorbar.html library(ggplot2) df <- data.frame( trt = factor(c(1, 1, 2, 2)), resp = c(1, 5, 3, 4), group = factor(c(1, 2, 1, 2)), se = c(0.1, 0.3, 0.3, 0.2)) ## The following three lines work fine and produce the same graphic as seen on the example website limits <- aes(max = resp + se, min=resp - se, width=0.9) p <- ggplot(df, aes(colour=group, y=resp, x=trt)) p + geom_point() + geom_errorbar(limits, width=0.2) ##However, the following line fails with: ## 'Error in eval(expr, envir, enclos) : object "group" not found' p + geom_point() + geom_errorbar(limits, width=0.2) +geom_abline(slope=0,intercept=3,linetype=2) ##If I remove colour from the plot, abline works but now there are black lines connecting the error bars p <- ggplot(df, aes(y=resp, x=trt)) p + geom_point() + geom_errorbar(limits, width=0.2) +geom_abline(slope=0, intercept=3,linetype=2)
James D Forester wrote:> > Hi all, > > I have run into what appears to be a bug in ggplot2; however, I am new > to the ggplot syntax, so I might be missing a key element. The main > issue is that I cannot get geom_abline to plot when colour is used to > identify "group" in the main plot. When I remove colour, geom_abline > works but the error bars have an undesirable line drawn between the left > edges of the caps. Does anyone know how to change this behavior? > >In http://www.nabble.com/plot-graph-with-error-bars-trouble-tf4535734.html Hadley Wickham says that this is a bug, fixed in the development version. However, I don't see that the update has propagated to my usual CRAN mirror yet ... -- View this message in context: http://www.nabble.com/ggplot2%3A-problem-with-geom_errorbar-and-geom_abline-tf4563163.html#a13030044 Sent from the R help mailing list archive at Nabble.com.