Reputation: 647
I would like to use ggplot to plot my result of the association of air pollutant with birth weight changes (95%CI).
the format of my data is like this
variable exposure period coef coef_lb coef_ub
PM10 entire pregnancy -27.6 -49.2 -3.8
SO2 entire pregnancy 40 14.2 62.8
NO entire pregnancy -26 -44 -6.4
NO2 entire pregnancy 0 -20 19
PM10 trimester1 -29.4 -49.4 -8
SO2 trimester1 12 -9 31.8
NO trimester1 5.2 -15.2 28.2
NO2 trimester1 -2.2 -23 16.6
PM10 trimester2 -11.8 -35.2 11.2
SO2 trimester2 26.2 2 51.4
NO trimester2 -10.8 -35.2 12.4
NO2 trimester2 -7.4 -27.8 14.6
PM10 trimester3 6.2 -17.6 28.2
SO2 trimester3 0.6 -19 22.4
NO trimester3 -24 -43 -5.4
NO2 trimester3 7 -11.4 26.8
I have four types of air pollutants, exposure period is trimester-specific, and I have the coef, and the lower bound and upper bound of 95%CI.
I want to plot a graph like the one below, can anyone help?
Upvotes: 1
Views: 1546
Reputation: 1866
#get the data.frame
data <- read.table("DATA.csv",header=T,sep=";")
require(ggplot2)
#build and plot ggplot object
g <- ggplot(data=data,aes(x=exposureperiod,y=coef))
g <- g + facet_grid(.~variable)
g <- g + geom_errorbar(aes(ymin=coef_lb,ymax=coef_ub))
g
Upvotes: 2