r - Sub Column Names on Grid Extra -


i'm trying create table using gridextra package in r, , want have sub column names under general column name. example have 1 large column titled "urbana-champaign" spans on 2 smaller column names "element" , "number of genes." have looked everywhere on gridextra support site can't seem find way create overall column names encompass subcolumns. know how?

it's rather easy basic gtable, , add new text it, you'd have add formatting , styling of cells. that's give -- way many parameters , options take care of.

library(gtable) gtable_add_grobs <- gtable_add_grob #misleading name  d <- head(iris, 3)  extended_matrix <- cbind(c("", rownames(d)), rbind(colnames(d), as.matrix(d)))   all_grobs <- matrix(lapply(extended_matrix, textgrob), ncol=ncol(d) + 1)  row_heights <- function(m){   do.call(unit.c, apply(m, 1, function(l)     max(do.call(unit.c, lapply(l, grobheight))))) }  col_widths <- function(m){   do.call(unit.c, apply(m, 2, function(l)     max(do.call(unit.c, lapply(l, grobwidth))))) }  g <- gtable_matrix("table", grobs=all_grobs,                    widths=col_widths(all_grobs) + unit(4,"mm"),                     heights=row_heights(all_grobs) + unit(4,"mm"))  g <- gtable_add_rows(g, unit(1, "line"), 0) g <- gtable_add_grobs(g, list(textgrob("sepal's main title"),                                textgrob("petal's main title"))                      t=1,b=1,l=c(2, 4), r=c(3, 5))  grid.newpage() grid.draw(g) 

enter image description here


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -