Grid.Table and Tablegrob in Gridextra Package

grid.table and tableGrob in gridExtra package

This recent answer shows how to alter the parameters, and Baptiste gives a link to further examples. As you notice in your question, to alter the formatting you use the theme argument; you can see what parameters to alter by looking at the output of ttheme_default()

# New theme paramters
myt <- ttheme_default(
# Use hjust and x to left justify the text
# Alternate the row fill colours
core = list(fg_params=list(hjust = 1, x=1),
bg_params=list(fill=c("yellow", "pink"))),

# Change column header to white text and red background
colhead = list(fg_params=list(col="white"),
bg_params=list(fill="red"))
)

# Example data - create some large numbers
dat <- mtcars[1:5,1:5]
dat$mpg <- dat$mpg*1000

grid.newpage()
grid.draw(tableGrob(format(dat, big.mark=","), theme=myt, rows=NULL))

The big.mark argument of format is used to add the comma separator, and rownames are removed using the rows=NULL argument.

Sample Image

Changing Header Row position in grid.table in R

you can split and recombine the gtable,

tg = tableGrob(df,rows=NULL)
grid::grid.draw(rbind(tg[2:nrow(tg),], tg[1,]))

How to Change Table Background with tableGrob in GridExtra

There's no background if you use grid::grid.draw(tableGrob()) (or grid.table() directly). plot.gtable, adding the grey background, is meant for debugging only.



Related Topics



Leave a reply



Submit