代码之家  ›  专栏  ›  技术社区  ›  Pryore

r-将grid.table中的列指定为粗体

  •  0
  • Pryore  · 技术社区  · 7 年前

    我有一个有3列的表,我正在使用grid.table生成一个pdf版本。我希望其中两列为粗体,另一列为纯文本。我还没有找到一个通用的解决方案,grid.table cran页面只显示如何编辑行或特定单元格的字体。

    使用小样本数据集(由于敏感性):

    > dput(Data)
    structure(list(Location = structure(c(1L, 1L, 1L, 2L, 2L, 3L), .Label = c("A", "B", "C"), class = "factor"), 
    Subloc = structure(1:6, .Label = c("A1","A2", "A3", "B1", "B2", "C1"), 
    class = "factor"), Type = structure(c(3L,3L, 3L, 1L, 1L, 2L), 
    .Label = c("Alpha", "Beta", "Meta"), 
    class = "factor")), 
    class = "data.frame", 
    row.names = c(NA, -6L))
    

    我的现有代码:

        maxrow <- c(30);
        npages <- ceiling(nrow(Data)/maxrow);
        pdf(paste0("DATE.pdf"), height = 11, width = 10)
        idx <- seq(1, maxrow)
        grid.table(Data[idx, ], rows = NULL, theme = ttheme_minimal(core=list(fg_params=list(hjust=0, x=0.1, fontface = c("bold"))),
                                                               rowhead=list(fg_params=list(hjust=0, x=0)), colhead=list(fg_params=list(fontsize = 14, col="#660066", fontface="bold"))))
        for (i in 2:npages){
         grid.newpage();
        if(i*maxrow <= nrow(Data)) {
        idx <- seq(1+((i-1)*maxrow), i*maxrow)}  else{
           idx <- seq(1+((i-1)*maxrow), nrow(Data))}grid.table(Data[idx,], rows =NULL,theme = ttheme_minimal(core=list(fg_params=list(hjust=0, x=0.1)), rowhead=list(fg_params=list(hjust=0, x=0)),colhead=list(fg_params=list(fontsize = 14, col="#660066", fontface="bold"))))
    }dev.off()
    

    我想使位置和类型列(而不是列标题)中的数据为粗体。我已经设法在fg_params=列表包装器中将所有列内容加粗,但不知道如何指定要对其进行此处理的列。

    1 回复  |  直到 7 年前
        1
  •  2
  •   user10697133    7 年前
    试试这个< /P>
    库(gridExtra)
    
    tt<-ttheme_默认值()
    tt$core$fg_参数<-列表(fontface=矩阵(c(1,2,3),ncol=ncol(d),nrow=nrow(d),byrow=true)
    
    grid.table(d,theme=tt)
    < /代码> 
    
    

    代码输出:

    代码输出:

    enter image description here