Home > other >  Add different labels in forest plot based on the cut-off line
Add different labels in forest plot based on the cut-off line

Time:12-16

I need to add two labels in my forest plot (I'm using the forestplot package) to distinguish the group below (No) from the group above (Yes) the cut-off line at 1.

Here are the data

library(forestplot)
dataout
              variables mean lower upper
             Mother    0.9411774 0.8968472 0.9876988
            sibling    0.8714648 0.7983499 0.9512757
                 X1    1.1250240 1.0106318 1.2523641
                 X2    1.1792050 1.0062237 1.3819239
                 X3    1.0473570 0.8227960 1.3332062
                 X4    1.5371143 1.2682586 1.8629644
                 X5    1.3714805 1.1762861 1.5990656
                 X6    0.8939320 0.7480613 1.0682473
                 X7    0.7126186 0.5683382 0.8935264

#this is the code to draw the plot:

 dataout |>
      forestplot(labeltext = variables,
                 zero = 1,
                 xlog = TRUE,
                 vertices = TRUE,
                 boxsize = 0.2) |>
      fp_set_style(box = "royalblue",
                   line = "darkblue",
                   summary = "royalblue") |>
      fp_set_zebra_style("#EFEFEF")

This is what I want to achieve: enter image description here

CodePudding user response:

We could something like this: Remember with dev.off() we could clean:

library(forestplot)
dev.off()
dataout |>
  forestplot(labeltext = variables,
             zero = 1,
             xlog = TRUE,
             vertices = TRUE,
             boxsize = 0.2) |>
  fp_set_style(box = "royalblue",
               line = "darkblue",
               summary = "royalblue") 
grid.text("No", .3, .95, gp=gpar(cex=1.5))
grid.text("Yes", .75, .95, gp=gpar(cex=1.5))

data

structure(list(variables = c("Mother", "sibling", "X1", "X2", 
"X3", "X4", "X5", "X6", "X7"), mean = c(0.9411774, 0.8714648, 
1.125024, 1.179205, 1.047357, 1.5371143, 1.3714805, 0.893932, 
0.7126186), lower = c(0.8968472, 0.7983499, 1.0106318, 1.0062237, 
0.822796, 1.2682586, 1.1762861, 0.7480613, 0.5683382), upper = c(0.9876988, 
0.9512757, 1.2523641, 1.3819239, 1.3332062, 1.8629644, 1.5990656, 
1.0682473, 0.8935264)), class = "data.frame", row.names = c(NA, 
-9L))

enter image description here

  • Related