Forest Plot in R-Quick Guide

Forest Plot in R, A forest plot, also known as a “blobbogram,” is used in meta-analyses to combine the findings of multiple research into a single figure.

In the previous article we discussed about Not Satisfied with statistical significance (p-value) »

The value of interest in the studies is shown on the x-axis (typically an odds ratio, an effect size, or a mean difference), and the findings from each individual study are shown on the y-axis.

This kind of map provides an easy method to see the outcomes of numerous research at once.

The example that follows demonstrates how to make a forest plot in R.

Example: Forest Plot in R

We must first establish a data frame to retain the effect size (or other value of interest) and the upper and lower confidence intervals for each research before we can use R to create a forest plot.

How to Apply AI to Small Data Sets? »

Let’s create data

df <- data.frame(study=c('M1', 'M2', 'M3', 'M4', 'M5'),
                 index=1:5,
                 effect=c(-.3, -.2, -.18, .18, .15),
                 lower=c(-.43, -.29, -.17, -.02, .04),
                 upper=c(-.32, -.11, -.04, .32, .24))

Now we can view the data frame

head(df)
   study index effect lower upper
1    M1     1  -0.30 -0.43 -0.32
2    M2     2  -0.20 -0.29 -0.11
3    M3     3  -0.18 -0.17 -0.04
4    M4     4   0.18 -0.02  0.32
5    M5     5   0.15  0.04  0.24

Next, we can make the following forest plot using the ggplot2 data visualisation package’s functions.

The Role of Data Science in Preventing Fraud »

Let’s load ggplot2

library(ggplot2)

Now we can create a forest plot

ggplot(data=df, aes(y=index, x=effect, xmin=lower, xmax=upper)) +
  geom_point() +
  geom_errorbarh(height=.1) +
  scale_y_continuous(name = "", breaks=1:nrow(df), labels=df$study)

Each study’s effect size is shown on the x-axis, and its name is shown on the y-axis.

Importance of Data Cleaning in Machine Learning »

Each study’s effect size is represented by a point on the plot, and the error bars illustrate the confidence interval boundaries.

In order to improve the visual appeal of the chart, we can also add a title, change the axis names, and add a vertical line with an effect size of zero:

Now we can do some beautification in the forest plot.

ggplot(data=df, aes(y=index, x=effect, xmin=lower, xmax=upper)) +
  geom_point() +
  geom_errorbarh(height=.1) +
  scale_y_continuous(breaks=1:nrow(df), labels=df$study) +
  labs(title='Effect Size by Study', x='Effect Size', y = 'Study') +
  geom_vline(xintercept=0, color='black', linetype='dashed', alpha=.5) +
  theme_minimal()

You are able to change the plot’s theme to suit your preferences. For an even more traditional aesthetic, we could also use theme classic().

Surprising Things You Can Do With R »

ggplot(data=df, aes(y=index, x=effect, xmin=lower, xmax=upper)) +
  geom_point() +
  geom_errorbarh(height=.1) +
  scale_y_continuous(breaks=1:nrow(df), labels=df$study) +
  labs(title='Effect Size by Study', x='Effect Size', y = 'Study') +
  geom_vline(xintercept=0, color='black', linetype='dashed', alpha=.5) +
  theme_classic()

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

six − 2 =