Is it possible to color the "points" in the L'abbé plot? I am using the metafor package.
# Load package
library(metafor)
# Load data
data(dat.bcg)
# Code
ex <- rma(ai=tpos, bi=tneg, ci=cpos,
di=cneg, data=dat.bcg, measure="OR",
slab=paste(author, year, sep=", "), method="FE")
# L'abbé plot
labbe(ex, transf = exp, ylab="Test group", xlab="Control")
Would it be possible to color the points based on a variable?
Fx blue colored points that represent:
dat.bcg$alloc==random
Thank you, C.
You could try the following:
dat.bcg$var[dat.bcg$alloc == "random"] <- "blue"
labbe(ex, transf = exp, ylab = "Test group", xlab = "Control", bg = dat.bcg$var)
And without the transformation:
labbe(ex, ylab = "Test group", xlab = "Control", bg = dat.bcg$var, grid = TRUE)
We can see that there are 7 blue points for the 7 instances where dat.bcg$alloc == "random"
.
Another option to distinguish between the points:
labbe(ex, ylab = "Test group", xlab = "Control", grid = TRUE, pch = dat.bcg$alloc)
To change the color of all three points you could do the following:
dat.bcg$var[dat.bcg$alloc == "random"] <- "blue"
dat.bcg$var[dat.bcg$alloc == "alternate"] <- "green"
dat.bcg$var[dat.bcg$alloc == "systematic"] <- "red"
Or with dplyr
we can use case_when
:
library(dplyr)
dat.bcg <- dat.bcg %>%
mutate(var = case_when(alloc == "random" ~ "blue",
alloc == "alternate" ~ "green",
alloc == "systematic" ~ "red",
TRUE ~ as.character(NA)))