Laura Bonnett
2011-Aug-22 13:03 UTC
[R] Multiple forest plots with the same x-axis and colour coded estimates and lines
Dear all, I would like to draw three forest plots to represent results at years 1, 2 and 3. I have the data as point estimates and 95% confidence intervals. Using the following code I can get three basic forest plots - the first which has the table of results. I have to plot each separately as the usual par(mfrow=c(3,1)) does not work with the function forestplot within rmeta. I can easily put them next to one another within powerpoint or similar though so that's not a problem. #Read data in dattabrem1 <- read.table("risk factors rem1.txt",header=TRUE) # year 1 results dattabrem2 <- read.table("risk factors rem2.txt",header=TRUE) # year 2 results dattabrem3 <- read.table("risk factors rem3.txt",header=TRUE) # year 3 results # Set up table of results for the three plots plotextr <- rbind(c("Age","Gender","Seizures","Treatment"),c("10","M","2","CBZ"),c("10","F","2","CBZ"), c("10","M","2","LTG"),c("10","F","2","LTG"),c("10","M","10","CBZ"),c("10","F","10","CBZ"), c("10","M","10","LTG"),c("10","F","10","LTG"),c("40","M","2","CBZ"),c("40","F","2","CBZ"), c("40","M","2","LTG"),c("40","F","2","LTG"),c("40","M","10","CBZ"),c("40","F","10","CBZ"), c("40","M","10","LTG"),c("40","F","10","LTG"),c("75","M","2","CBZ"),c("75","F","2","CBZ"), c("75","M","2","LTG"),c("75","F","2","LTG"),c("75","M","10","CBZ"),c("75","F","10","CBZ"), c("75","M","10","LTG"),c("75","F","10","LTG")) # 1 year results estimate1y <- c(NA,dattabrem1$HR) lowerd1y <- c(NA,dattabrem1$CIlower) upperd1y <- c(NA,dattabrem1$CIupper) # 2 year results estimate2y <- c(NA,dattabrem2$HR) lowerd2y <- c(NA,dattabrem2$CIlower) upperd2y <- c(NA,dattabrem2$CIupper) # 3 year results estimate3y <- c(NA,dattabrem3$HR) lowerd3y <- c(NA,dattabrem3$CIlower) upperd3y <- c(NA,dattabrem3$CIupper) # Draw forest plots forestplot(plotextr,estimate1y,lowerd1y,upperd1y,is.summary=c(TRUE,rep(FALSE,24)),zero="",align="c",xlab="Remission @ 1 year") forestplot(plotext2r,estimate2y,lowerd2y,upperd2y,zero="",xlab="Remission @ 2 years") forestplot(plotext2r,estimate3y,lowerd3y,upperd3y,zero="",xlab="Remission @ 3 years") Having managed to obtain these basic plots I need the x-axes to be the same. Usually xlim would be sufficient to do this but this function is not avaialble within forestplot so does anyone know how I can make the x-axes the same over all the plots? Additionally, within each plot, two treatments are compared (top two blocks are treatment 1, 2nd 2 blocks are treatment 2, next 2 are treatment 1 etc.) Is there any way I can colour code the boxes to show this? Many thanks, Laura P.S. I'm using Windows, R 2.9.2 [[alternative HTML version deleted]]