Zane
Zane

Reputation: 69

gridExtra rotate row names and arrange column names

I have two questions

1.When I use tableGrob to set multiple row names for arrangeGrob, how can I rotate the names, I noticed someone has posted a similar question R grid.table column heading character rotation. However, I failed here

library(grid)
library(gridExtra)
gs <- lapply(1:9, function(ii)
grobTree(rectGrob(gp=gpar(fill=ii, alpha=0.5)), textGrob(ii)))
gR <- arrangeGrob(grobs=gs, ncol=4,
                  top="top label",
                  right="right label")
tt <- ttheme_default(base_size = 8,
                     rowhead=list(fg_params=list(rot=90)))
lt <- tableGrob(c("", "134442243", "5425376", "938372378"),
                theme = tt)
cb <- cbind(lt, gR, size = "last")
grid.newpage()
grid.draw(cb)

2.When I set multiple xlabels for arrangeGrob as following, the grobs are quite narrow

tt <- ttheme_default(colhead=list(fg_params = list(parse=F)))
bt <- tableGrob(matrix(c("    1    ", "2", "3", "4", ""),ncol = 5), theme = tt)
rb <- rbind(gR, bt, size = "last")
# the width of each grob is changed by `bt`
grid.newpage()
grid.draw(rb)

It seems each grob width is related to each xlabel width. How can I keep grob width and put xlabel at the middle bottom of grob?

Upvotes: 0

Views: 849

Answers (1)

user10205239
user10205239

Reputation: 26

the data you pass to tableGrob has no row names, it's just a vector, which is themed by the core argument,

tt <- ttheme_default(base_size = 8,
                     core = list(fg_params=list(rot=90)))

If you want the first gtable to set the widths of the combined gtable, use "first" rather than "last"

rbind(gR, bt, size = "first")

Upvotes: 1

Related Questions