i have following issues when using nice feature tablegrob()
gridextra
package plot table in html document produced rmarkdown , knitr
.
here reproducible example:
library(datasets) library(dplyr) mtcars$cyl <- as.factor(mtcars$carb) carb.mpg <- mtcars %>% select(carb,mpg) %>% group_by(carb) %>% summarise_each(funs(sum(.,na.rm=true)),-carb) %>% arrange(desc(mpg)) ##plot table tab <- tablegrob(carb.mpg, cols=c("carb","mpg"), theme=ttheme_minimal()) grid.arrange(tab, top=textgrob("cars mpg per carb",gp=gpar(fontsize=16,font=1)) )
for knitr
general chunk options:
title: "test cars" output: html_document: keep_md: true
{r setoptions, echo=false} library(knitr) opts_chunk$set(message=false,warning=false)
the issue can been seen attached snapshot huge space between table , title , legend. nice if left-align table in document.
any appreciated.
you try this
tg <- textgrob("cars mpg per carb", gp=gpar(fontsize=16,font=1)) grid.arrange(tg, tab, heights=unit.c(grobheight(tg), sum(tab$heights)), vp=viewport(x=unit(0,"npc") + 0.5*unit.pmax(grobwidth(tg), sum(tab$widths))))
Comments
Post a Comment