Plotting 95% CI using geom_errorbars

set.sed(12345)
beta<-runif(n = 5,min = 1,max = 3)
beta
upper.ci<-beta+0.25
upper.ci
lower.ci<-beta-0.25
samp.n<-rep(x = 10,5)
samp.n
data<-data.frame(samp.n,beta,lower.ci,upper.ci)
data
data$group<-rownames(data)<-paste0(“drug”,1:5)
data$group<-factor(data$group)
str(data)
format(data,digits=3) # 2 decimals
library(ggplot2)
plot.b<-ggplot(data,aes(x=group,y=beta))
plot.b1<-plot.b+geom_errorbar(aes(ymin=lower.ci,ymax=upper.ci))
plot.b1
#prettier
plot.c<-ggplot(data,aes(x=group,y=beta,colour=group)) #colour based on group
plot.c1<-plot.c+geom_errorbar(aes(ymin=lower.ci,ymax=upper.ci),width=0.3) #width = width of end of bars
plot.c1

#make points bigger and nicer
point.c<-geom_point(size=3,shape=21,fill=’white’)
#different shape
point.c.sp<-geom_point(aes(shape=group),size=5)

#c1 and point
plot.c2<-plot.c1+point.c
plot.c2

#redo
plot.c1+geom_point()
plot.c1+geom_point(aes(shape=group))

#or
plot.c1+point.c.sp

#excellent ref = http://docs.ggplot2.org/0.9.3.1/geom_point.html,

#http://www.cookbook-r.com/Graphs/Plotting_means_and_error_bars_(ggplot2)/