Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to show the title of a table with tableGrob?

Tags:

r

gridextra

grob

Consider this example

library(gridExtra)
library(grid)

d1 <- head(iris[,1:3]) %>% as_tibble()
d2 <- head(iris[,2:5]) %>% as_tibble()

grid.arrange(tableGrob(d1),
             tableGrob(d2))

which gives enter image description here

This is really nice but I am missing the titles of the dataframes! How can I add them to the picture automatically?

Thanks!

like image 602
ℕʘʘḆḽḘ Avatar asked Jan 27 '23 21:01

ℕʘʘḆḽḘ


1 Answers

You can use ggplot,

library(ggplot2)

dd1 <- ggplot() + annotation_custom(tableGrob(d1)) + labs(title = 'd1')
dd2 <- ggplot() + annotation_custom(tableGrob(d2)) + labs(title = 'd2')
grid.arrange(dd1, dd2, nrow = 2)

enter image description here

like image 95
Sotos Avatar answered Feb 12 '23 05:02

Sotos