1

I'm trying to underline my headers for my columns of my forestplot, which I've created with the forestplot() function from the library(forestplot) package.

this is a excerpt of the settings i already have with the plot. I've changed the header fontface from its default "bold" to "plain" in the last line of code below, in the 'summary=' object. Unfortunately gpar(fontface="") doesn't seem to have an "underline" option.

library(forestplot)
base_data |>
 forestplot(labeltext = c(text, results),
            zero=1,
  col = fpColors(zero="black"),
            txt_gp = fpTxtGp(label = gpar(fontfamily = "Arial"),
                             ticks=gpar(cex=1),
                             xlab=gpar(cex=1),
                             summary=gpar(fontface="plain")))

Anyone have any suggestions?

zx8754
  • 52,746
  • 12
  • 114
  • 209
dkong
  • 13
  • 2
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jul 17 '23 at 19:40
  • @MrFlick I am assuming the data is from the package repo: https://github.com/gforge/forestplot/blob/master/vignettes/forestplot.Rmd#L65C1-L72C92 – zx8754 Jul 17 '23 at 19:42
  • @zx8754 There are no `text` or `results` columns in the data from that vignette. – MrFlick Jul 17 '23 at 19:44
  • @MrFlick correct, just noticed. Still could be used as example, the question is about the header. – zx8754 Jul 17 '23 at 19:50

1 Answers1

1

We can use expression with underline, in this example I am underlining "Study":

library(forestplot)

# example data is from the package's vignette:
# https://github.com/gforge/forestplot/blob/master/vignettes/forestplot.Rmd#L65

base_data |>
  forestplot(labeltext = c(study, deaths_steroid, deaths_placebo, OR),
             clip = c(0.1, 2.5),
             xlog = TRUE) |>
  fp_add_header(study = c("", expression(underline(Study))),
                deaths_steroid = c("Deaths", "(steroid)"),
                deaths_placebo = c("Deaths", "(placebo)"),
                OR = c("", "OR"))

enter image description here

zx8754
  • 52,746
  • 12
  • 114
  • 209
  • 1
    perfect. thank you! just to add for anyone who might need this too: if using a phrase rather than one word you need to put the phrase in ` ` , ie. expression(underline( ` Study Results ` )) – dkong Jul 17 '23 at 20:06