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.
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
Specifying the Colour Scale for Maps in Ggplot
Remove Multiple Patterns from Text Vector R
Plot Only One Side/Half of the Violin Plot
Rstudio Shiny Not Able to Use Ggvis
Shiny App File Upload: How to Save the Files Uploaded on a Shiny Gui to a Particular Destination
How to Write a Data-Frame with One Column a List to a File
Using Data.Table to Create a Column of Regression Coefficients
How to Convert a Hex String to Text in R
Paste Several Column Values into One Value in R
Control Number Formatting in Shiny's Implementation of Datatable
Forest Plot with Table Ggplot Coding
Ggplot2: How to Reduce Space Between Narrow Width Bars, After Coord_Flip, and Panel Border
Note or Warning from Package Check When Readme.Md Includes Images
How to Scrape a Table with Rvest and Xpath
R: How to Aggregate Some Columns While Keeping Other Columns