grid.table and tableGrob in gridExtra package

前端 未结 1 896
情话喂你
情话喂你 2021-01-04 14:31

I am trying to format the table using gridExtra package. The gridExtra package I have is 2.0 and R version is 3.2.1

I was goin

相关标签:
1条回答
  • 2021-01-04 14:44

    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.

    0 讨论(0)
提交回复
热议问题