[R] Error Bars ggplot2

John Kane jrkrideau at inbox.com
Thu Jul 26 18:25:17 CEST 2012


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


> -----Original Message-----
> From: adamjgabbert at gmail.com
> Sent: Thu, 26 Jul 2012 09:03:44 -0400
> To: r-help at r-project.org
> Subject: [R] Error Bars ggplot2
> 
> 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
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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



More information about the R-help mailing list