Search code examples
rr-forestplot

Making single element bold in forestplot


I want to make certain text elements bold in my forestplot column text. This is very similar to this question, but slightly different because I only want one item bolded.

Using a combination of expression(bold()) I have been able to do so:

library(forestplot)
cochrane_from_rmeta <- 
  structure(list(
    mean  = c(NA, 0.578, 0.165, 0.246, 0.700, 0.348, 0.139, 1.017), 
    lower = c(NA, 0.372, 0.018, 0.072, 0.333, 0.083, 0.016, 0.365),
    upper = c(NA, 0.898, 1.517, 0.833, 1.474, 1.455, 1.209, 2.831)),
    .Names = c("mean", "lower", "upper"), 
    row.names = c(NA, -8L), 
    class = "data.frame")
tabletext <- cbind(
  c("Study", "Auckland", "Block", 
    "Doran", "Gamsu", "Morrison", "Papageorgiou", 
    "Tauesch"),
  c("Deaths", "36", "1", 
    "4", "14", "3", "1", 
    "8"),
  c("OR", "0.58", "0.16", 
    "0.25", "0.70", "0.35", "0.14", 
    "1.02"))
tabletext_lists <- list(list(), list(), list())
        tabletext_lists[[1]] <- tabletext[,1]
        tabletext_lists[[2]] <- tabletext[,2]
        tabletext_lists[[3]] <- tabletext[,3]
        tabletext_lists[[3]][3] <- list(expression(bold("0.16")))
        tabletext_lists[[3]][7] <- list(expression(bold(tabletext_lists[[3]][7])))

forestplot(tabletext_lists,
           cochrane_from_rmeta,new_page = TRUE,
           clip = c(0.1,2.5),
           xlog = TRUE,
           col = fpColors(box = c(rep("royalblue", 5), "red", "red"),
                          line = "darkblue"))

Which yields this figure:

enter image description here

I cannot figure out how to make the item of interest appear bold without manually entering it in such as tabletext_lists[[3]][3] <- list(expression(bold("0.16")))

Is there a way to make individual elements bold without using the is.summary parameter from forestplot? And as such is it possible to do so without having to manually enter the text value itself and do so by slicing or normal selection from a vector?


Solution

  • You can use in forestplot the txt_gp option. List1 is a 2-dimensionnal matrix where list[[row]][[column]] is a gpar(fontface="bold") or gpar(fontface="plain"). In the forestplot, it will put as bold or plain the element of interest.

    For instance, in your case, list1[[1]][[1]] is for the element Auckland and should be set as plain.

    forestplot(tabletext, 
             txt_gp=(label=fpTxtGp(list1))
    )