Skip to content

Error Bars ggplot2

2 messages · Adam Gabbert, John Kane

#
Hello,

I'm attempting to plot error bars side by side rather than stacked on top
of each other with ggplot2.  Here is the sample code I am using:

#Code

#Data
spd<-c("s","f","f","s","f","s","s","s","f","f","s","f")
r<-c(4.9,3.2,2.1,.2,3.8,6.4,7.5,1.7,3.4,4.1,2.2,5)

#Turn spd into a factor
spd.f<-factor(spd)

#Place data into a data frame
data<-data.frame(cbind(spd.f,r))

#Load ggplot2
library(ggplot2)

#Create plot
pd<-position_dodge(.2)
myplot<-ggplot(data,aes(x=spd,y=r,colour=spd))+
  geom_errorbar(aes(ymin=3,ymax=5),width=.1)+
  geom_point()+
  geom_errorbar(aes(ymin=1,ymax=6),width=.1,colour="black",position=pd)
#Display plot
myplot

I have attached a plot that my sample code produces.  As you can see the
error bars are stacked.  How can I get them to plot side by side?

Thanks

AG
#
Is this what you mean?
dat1  <- data.frame( spd = c("s","f","f","s","f","s","s","s","f","f","s","f"),
                r = c(4.9,3.2,2.1,.2,3.8,6.4,7.5,1.7,3.4,4.1,2.2,5))

myplot<-ggplot(dat1, aes(spd, r, colour = spd)) +
  geom_errorbar(aes(ymin=3, ymax=5), width=.1) +
  geom_point()  + coord_flip()

John Kane
Kingston ON Canada
____________________________________________________________
GET FREE 5GB EMAIL - Check out spam free email with many cool features!
Visit http://www.inbox.com/email to find out more!