3

I am trying to change the background color of my title. I have followed this code which results to adding a title on top of my tableGrob. However, the fill option is not enabled. No warning or error posted in R (v3.2.5).

d <- head(iris[,1:2])
table <- tableGrob(d, rows=NULL)

library(grid)
library(gtable)

title <- grid.text("Testing title background",gp=gpar(fontsize=15, col="white", fontface="bold", fill="black"))

table <- gtable_add_rows(table, 
                         heights = grobHeight(title) + unit(1,"line"),
                         pos = 0)
table <- gtable_add_grob(table, title,
                         t=1, l=1, 
                         r=ncol(table))

plot(table)

I need the title in White bold letters and in black background.

Any help is much appreciated. Thank you.

KRStam
  • 393
  • 5
  • 18

1 Answers1

5

Solution given by @user20650:

write the text on a black rectangle: title <- grobTree( rectGrob(gp=gpar(fill="black")), textGrob("Testing title background", gp=gpar(fontsize=15, col="white", fontface="bold"))) (and use grid.draw)

KRStam
  • 393
  • 5
  • 18