forked from MathiasHarrer/Doing-Meta-Analysis-in-R
-
Notifications
You must be signed in to change notification settings - Fork 0
/
04-forest_plots.Rmd
167 lines (124 loc) · 4.86 KB
/
04-forest_plots.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Forest Plots {#forest}
![](_figs/forest.jpg)
```{block,type='rmdinfo'}
Now that we created the **output of our meta-analysis** using the `metagen`, `metacont` or `metabin` functions in `meta` (see [Chapter 4.1](#fixed),[Chapter 4.2](#random) and [Chapter 4.3](#binary)), it is time to present the data in a more digestable way.
**Forest Plots** are an easy way to do this, and it is conventional to report forest plots in meta-analysis publications.
```
<br><br>
---
## Generating a Forest Plot
To produce a forest plot, we use the meta-analysis output we just created (e.g., `m`, `m.raw`) and the `meta::forest()` function. I will use my `m.hksj.raw` output from [Chapter 4.2.3](#random.raw) to create the forest plot.
```{r,echo=FALSE,warning=FALSE,message=FALSE}
load("_data/metacont_data.RData")
metacont$Ne<-as.numeric(metacont$Ne)
metacont$Me<-as.numeric(metacont$Me)
metacont$Se<-as.numeric(metacont$Se)
metacont$Mc<-as.numeric(metacont$Mc)
metacont$Sc<-as.numeric(metacont$Sc)
library(meta)
library(metafor)
m.hksj.raw<-metacont(Ne,
Me,
Se,
Nc,
Mc,
Sc,
data=metacont,
studlab=paste(Author),
comb.fixed = FALSE,
comb.random = TRUE,
method.tau = "SJ",
hakn = TRUE,
prediction=TRUE,
sm="SMD")
metacont$intervention.type<-c("PCI","PCI","Mindfulness","CBT","CBT","CBT")
```
```{r,fig.width=11,fig.height=4,fig.align='center'}
forest(m.hksj.raw)
```
Looks good so far. We see that the function plotted a forest plot with a **diamond** (i.e. the overall effect and its confidence interval) and a **prediction interval**.
There are plenty of **other parameters** within the `meta::forest` function which we can use to modify the forest plot.
```{r,echo=FALSE}
library(knitr)
library(grid)
load("_data/foresttable.RData")
kable(foresttable)
```
This is again just an overview. For all settings, type `?meta::forest` in your **Console** to see more.
**Let us play around with the function a little now:**
```{r,fig.width=9,fig.height=3.5,fig.align='center'}
forest(m.hksj.raw,
sortvar=TE,
xlim = c(-1.5,0.5),
rightlabs = c("g","95% CI","weight"),
leftlabs = c("Author", "N","Mean","SD","N","Mean","SD"),
lab.e = "Intervention",
pooled.totals = FALSE,
smlab = "",
text.random = "Overall effect",
print.tau2 = FALSE,
col.diamond = "blue",
col.diamond.lines = "black",
col.predict = "black",
print.I2.ci = TRUE,
digits.sd = 2
)
```
Looks good so far! For special **layout types**, proceed to [Chapter 5.2](#layouttypes) now.
<br><br>
---
## Layout types {#layouttypes}
The `meta::forest` function also has two **Layouts** preinstalled which we can use. Those layouts can be accessed with the `layout` parameter.
* **"RevMan5"**. This layout is used for Cochrane reviews and generated by *Review Manager 5*.
* **"JAMA"**. This layout gives you a forest plot according to the guidelines of the *Journal of the American Medical Association* as output (see details [here](https://jamanetwork.com/journals/jama/pages/instructions-for-authors)).
The **RevMan** layout looks like this:
```{r,fig.width=10,fig.height=4,fig.align='center'}
forest(m.hksj.raw,
layout = "RevMan5",
digits.sd = 2)
```
The **JAMA** layout looks like this:
```{r,fig.width=7,fig.height=3,fig.align='center'}
forest(m.hksj.raw,
layout = "JAMA",
text.predict = "95% PI",
col.predict = "black",
colgap.forest.left = unit(15,"mm"))
```
<br><br>
---
## Saving the forest plots
Let us say I want to save the JAMA version of my forest plot now. To do this, I have to reuse the code with which I plotted my forest plot, and put it between `pdf(file='name_of_the_pdf_i_want_to_create.pdf')` and `dev.off`, both in separate lines. This saves the plot into a PDF in my working directory. This way, I can export the plot in different formats (you can find more details on the saving options [here](#saving)).
<br></br>
**PDF**
```{r, eval=FALSE}
pdf(file = 'forestplot.pdf')
forest.jama <- forest(m.hksj.raw,
layout = "JAMA",
text.predict = "95% PI",
col.predict = "black",
colgap.forest.left = unit(15,"mm"))
dev.off()
```
**PNG**
```{r, eval=FALSE}
png(file = 'forestplot.png')
forest.jama <- forest(m.hksj.raw,
layout = "JAMA",
text.predict = "95% PI",
col.predict = "black",
colgap.forest.left = unit(15,"mm"))
dev.off()
```
**Scalable Vector Graphic**
```{r, eval=FALSE}
svg(file = 'forestplot.svg')
forest.jama <- forest(m.hksj.raw,
layout = "JAMA",
text.predict = "95% PI",
col.predict = "black",
colgap.forest.left = unit(15,"mm"))
dev.off()
```
<br><br>
---