# load data:
data("CrinsEtAl2014")
# compute effect sizes (log odds ratios) from count data
# (using "metafor" package's "escalc()" function):
crins.es <- escalc(measure="OR",
ai=exp.AR.events, n1i=exp.total,
ci=cont.AR.events, n2i=cont.total,
slab=publication, data=CrinsEtAl2014)
print(crins.es)
########################
# generate forest plots;
# with default settings:
forestplot(crins.es)
# exponentiate values (shown in table and plot), show vertical line at OR=1:
forestplot(crins.es, expo=TRUE, zero=1)
# logarithmic x-axis:
forestplot(crins.es, expo=TRUE, xlog=TRUE)
# show more decimal places:
forestplot(crins.es, digits=3)
# change table values:
# (here: add columns for event counts)
fp <- forestplot(crins.es, expo=TRUE, plot=FALSE)
labtext <- fp$labeltext
labtext <- cbind(labtext[,1],
c("treatment",
paste0(CrinsEtAl2014[,"exp.AR.events"], "/", CrinsEtAl2014[,"exp.total"])),
c("control",
paste0(CrinsEtAl2014[,"cont.AR.events"], "/", CrinsEtAl2014[,"cont.total"])),
labtext[,2:3])
labtext[1,4] <- "OR"
print(fp$labeltext) # before
print(labtext) # after
forestplot(crins.es, labeltext=labtext, expo=TRUE, xlog=TRUE)
# see also the "forestplot" help for more arguments that you may change,
# e.g. the "clip", "xticks", "xlab" and "title" arguments,
# or the "txt_gp" argument for label sizes etc.:
forestplot(crins.es, clip=c(-4,1), xticks=(-3):0,
xlab="log-OR", title="pediatric transplantation example",
txt_gp = fpTxtGp(ticks = gpar(cex=1), xlab = gpar(cex=1)))
###########################################################
# In case effects and standard errors are computed already
# (and normally one wouldn't need to call "escalc()")
# you can still use "escalc()" to assemble the plot, e.g.:
data("HinksEtAl2010")
print(HinksEtAl2010)
hinks.es <- escalc(yi=log.or, sei=log.or.se,
slab=study, measure="OR",
data=HinksEtAl2010)
forestplot(hinks.es)
Run the code above in your browser using DataLab