3

Is there a way to change the colour of complete rows in a forest plot based on text?

For example, in the plot below, I'd like to be able to have four different row colours, one for each of DEF, RU, MID & FWD in the Player column.

enter image description here

Joe
  • 8,073
  • 1
  • 52
  • 58
Morts81
  • 419
  • 3
  • 13

1 Answers1

3

The col argument can take a vector of colors. So, something like this should work:

library(metafor)

dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg)
cols <- c("red", "green", "blue")[match(dat$alloc, c("random", "alternate", "systematic"))]

forest(dat$yi, dat$vi, col=cols)
Wolfgang
  • 2,810
  • 2
  • 15
  • 29