I have a question similar to the one here, where OP aimed to merge the headers of the column present in the table horizontal merging. Here I wish to merge groups of cells which are vertically lined. The following is my target table design made in Microsoft Excel software:-
My attempt at making the target table using the method prescribed for question with horizontal merging
library(gridExtra)
library(grid)
library(ggplot2)
alphabets <- c(rep("A", 3), rep("B", 3), rep("C",3))
numbers <- c(rep(c(1,2,3), 3))
sounds <- c('Ayes','Bees','Cees')
df1 <- data.frame(alphabets = alphabets,numbers=numbers)
df2 <- data.frame(sounds = sounds)
tab1 <- tableGrob(df1,theme = ttheme_default(),row=NULL)
tab2 <- tableGrob(df2,theme = ttheme_default(),row=NULL)
halign <- combine(tab2,tab1, along =1)
grid.draw(halign)
This will give me the following output:-
I have a temporary work around for now. But it will fail if I am merging even number of cells.
sounds <- c('','Ayes','','','Bees','','','Cees','')
df2 <- data.frame(sounds = sounds)
tab2 <- tableGrob(df2,theme = ttheme_default(),row=NULL)
halign <- combine(tab2,tab1, along =1)
grid.draw(halign)
The output for this is:-
My question is how can you merge two table grob objects and keep the length of the largest table for the final output.
Thanks you for your efforts, the answers will greatly aid in the presentation of the results of my analysis.
Cheers
Lune3141