grid.tables中的两个字体 [英] Two font faces in grid.tables

查看:149
本文介绍了grid.tables中的两个字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 grid.table 对象来显示PowerBi中的数据框,下面是我的代码:

<
library(grid)
mydf< - data.frame(id = c(1:5) ),value = c(A,B,C,D,E))
mytheme <-ttheme_default(base_size = 10,
core = list(fg_params = list(hjust = 0,x = 0.01),
bg_params = list(fill = c(white,lightgrey)))

grid.table(mydf,cols = NULL,theme = mytheme,rows = NULL)

这是我的输出:





我想输出字体的样式,以便只有第一列的字体粗体,没有人知道如何实现这一点?



谢谢

解决 grid.table()仅仅是 grid.draw(tableGrob(...) code>



您可以通过一些Grob手术得到您想要的结果:

  library(grid)
library(gridExtra)

mydf< - data.frame(id = c(1:5),value = c(A, b,C,D,E))

mytheme <-ttheme_default(base_size = 10,
core = list(fg_params = list(hjust = 0 ,x = 0.01),
bg_params = list(fill = c(white,lightgrey)))

制作 tableGrob

  tg <  -  tableGrob(mydf,cols = NULL,theme = mytheme,rows = NULL)

编辑 tableGrob (第1列是前5个槽位):

 在1:5){
tg $ grobs [[i]]< - editGrob(tg $ grobs [[i]],gp = gpar(fontface =bold))
}

我喜欢用新页面作为例子,但是你可以从> grid.table()不使用它:

  grid.newpage()
grid.draw(tg)


I have created a grid.table object to display a dataframe in PowerBi, below there is my code:

library(reshape)
library(gridExtra)
library(grid)
mydf <- data.frame(id = c(1:5), value = c("A","B","C","D","E"))
mytheme <- ttheme_default(base_size = 10,
                          core=list(fg_params=list(hjust=0, x=0.01),
                                    bg_params=list(fill=c("white", "lightgrey"))))

grid.table(mydf,cols = NULL, theme = mytheme, rows = NULL)

and this is my output:

I would like to style the font of the output so that only the first column has the font in bold, does anyone knows how to achive this?

Thanks

解决方案

grid.table() is just a wrapper for grid.draw(tableGrob(...))

You can get your desired results with some Grob surgery:

library(grid)
library(gridExtra)

mydf <- data.frame(id = c(1:5), value = c("A","B","C","D","E"))

mytheme <- ttheme_default(base_size = 10, 
                          core = list(fg_params=list(hjust=0, x=0.01),
                                      bg_params=list(fill=c("white", "lightgrey"))))

Make the tableGrob:

tg <- tableGrob(mydf, cols = NULL, theme = mytheme, rows = NULL)

Edit the tableGrob (column 1 is first 5 slots):

for (i in 1:5) {
  tg$grobs[[i]] <- editGrob(tg$grobs[[i]], gp=gpar(fontface="bold"))
}

I like to use a new page for examples , but you can remove it since grid.table() doesn't use it either:

grid.newpage()
grid.draw(tg)

这篇关于grid.tables中的两个字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆