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)/

Showcases of graphs using Stata

From : Survey Design and Analysis Services (http://www.survey-design.com.au/index.html)

Below are some Stata graphs. These are presented as they have used Stata in some interesting ways.
From time to time more graphs will be added to this page. The graph below have generally be taken from the Statalist and in some cases the code has been slightly modified.
To see the original Statalist entry do a Google search on a line of code.

Stata Graphs

Simple graph using ggplot2 in R

Good short summary of doing graphs in R using ggplot2

1) scatterplot : http://rforpublichealth.blogspot.com/2013/11/ggplot2-cheatsheet-for-scatterplots.html

2) barplot : http://rforpublichealth.blogspot.com/2014/01/ggplot2-cheatsheet-for-barplots.html

3) checking distribution : http://rforpublichealth.blogspot.com/2014/02/ggplot2-cheatsheet-for-visualizing.html