smd2179 smd2179 - 1 month ago 10
R Question

Forest plot in R with both effect and no effect lines

I have made a forest plot in r using the forestplot package. The code is as follows:

#forestplot


labeltext2 <- c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "Summary Effect")

effect2 <- c(0.12, 0.61, 0.11, 0.25, 0.24, 0.63, 0.33, 0.41, 0.38, 0.52, 0.23, 0.47,
0.32, 0.36, 0.03, 0.15, 0.25, 0.67, 0.003, 0.32)


lower_2 <- c(0.08, 0.51, .03, 0.11, 0.06, 0.62, 0.11, 0.29, 0.18,
0.4, 0.19, 0.39, 0.24, 0.39, -0.13, 0.01, 0.09, 0.43,
-0.08, 0.19)

higher_2 <- c(0.16, 0.71, .19, 0.39, 0.42, 0.64, 0.55, 0.53, 0.58,
0.64, 0.27, 0.55, 0.4, 0.4, 0.19, 0.29, 0.41, 0.91,
0.08, 0.44)

forestplot(labeltext2, effect2, lower_2, higher_2, zero = .32,
cex = 2,
lineheight = "auto",
xlab = "effect size",
xticks = c(-.5, 0, .5, 1, 1.5),
title = "ForestPlot",
new_page = TRUE)


Which allows me to get this image:
Forestplot

This image has an effect line coming up at .32, the summary effect, using the zero argument. I would like to add an additional thick black line at 0 to show the "no-effect" line. Does anyone know how do this? I am open to using another package/function.

Thank you!

Answer

I can't figure out how the forestplot uses grid graphics, but here's a manual solution:

forestplot(labeltext2, effect2, lower_2, higher_2, zero = .32,
           cex = 2, 
           lineheight = "auto",
           xlab = "effect size",
           xticks = c(-.5, 0, .5, 1, 1.5),
           title = "ForestPlot",
           new_page = TRUE)

# Add line manually
x = .397
y0 = .12
y1 = .875
grid.lines(c(x, x), c(y0, y1), default.units = "npc",
           gp = gpar(lwd = 2))