Search code examples
rplotmetafor

Can the points be colored in the L'abbé-plot based on category in R metafor package?


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.


Solution

  • 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)
    

    enter image description here

    And without the transformation:

    labbe(ex, ylab = "Test group", xlab = "Control", bg = dat.bcg$var, grid = TRUE)
    

    enter image description here

    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)
    

    enter image description here

    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)))
    

    enter image description here