Skip to content

Instantly share code, notes, and snippets.

@hrbrmstr
Last active January 16, 2018 16:26
Show Gist options
  • Save hrbrmstr/bb93a8f2b378c6112fedbe581690bf21 to your computer and use it in GitHub Desktop.
Save hrbrmstr/bb93a8f2b378c6112fedbe581690bf21 to your computer and use it in GitHub Desktop.
library(grid)
library(gridExtra)
mydf <- data.frame(id = c(1:5), value = c("A","B","C","D","E"))
mytheme <- ttheme_default(base_size = 10,
core = list(fg_params=list(hjust=0, x=0.01),
bg_params=list(fill=c("white", "lightgrey"))))
tg <- tableGrob(mydf, cols = NULL, theme = mytheme, rows = NULL)
for (i in 1:5) {
tg$grobs[[i]] <- editGrob(tg$grobs[[i]], gp=gpar(fontface="bold"))
}
space <- 30 ; tg$widths[1] <- unit(max(unlist(lapply(tg$grobs[1:5], function(g) {convertWidth(grobWidth(g), "pt", TRUE)}))) + space, "pt")
grid.newpage()
grid.draw(tg)
library(grid)
library(gridExtra)
tg <- tableGrob(iris[1:5, 1:3])
for (i in c(19,24,29)) tg$grobs[[i]] <- editGrob(tg$grobs[[i]], gp=gpar(col="white"))
for (i in c(34,39,44)) tg$grobs[[i]] <- editGrob(tg$grobs[[i]], gp=gpar(fill="blue"))
grid.newpage()
grid.draw(tg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment