【问题标题】:How to add the grid in a table with white backround in r如何在r中的白色背景表中添加网格
【发布时间】:2020-03-26 02:53:47
【问题描述】:

我想用 gridExtra-Package 生成一个表格。此表应具有带网格图案的白色背景。下表有白色背景但没有网格。

y<-iris[1:4,1:5]

hj <- matrix(c(0.90,  0.90, 0.90, 0.90, 0.90), ncol=ncol(y), nrow=nrow(y), byrow=TRUE)
x <- matrix(c( 0.90, 0.90, 0.90, 0.90, 0.90), ncol=ncol(y), nrow=nrow(y), byrow=TRUE)
colours <- matrix("white", nrow(y), ncol(y))
colours[1:nrow(colours), 1] <- "#e9f1e9"

tt1 <- ttheme_default(core=list(fg_params=list(hjust = as.vector(hj),
            x = as.vector(x), fontface=c(rep("plain",ncol(y)))), bg_params = list(fill =colours , col=NA)))
tab<-tableGrob(y, rows = NULL, theme = tt1)
grid.newpage()
grid.draw(tab)

相比之下,此表具有所需的网格,但没有白色背景颜色。

g <- tableGrob(iris[1:4, 1:3])
grid.newpage()
grid.draw(g)

如何连接这两个表才能同时拥有?

【问题讨论】:

    标签: r grid


    【解决方案1】:

    这就是你要找的吗?将bg_params列表中的col=更改为"black"

    编辑

    现在换了背景颜色。根据您的评论。

    library(grid)
    library(gridExtra)
    y<-iris[1:4,1:5]
    hj <- matrix(c(0.90,  0.90, 0.90, 0.90, 0.90), ncol=ncol(y), nrow=nrow(y), byrow=TRUE)
    x <- matrix(c( 0.90, 0.90, 0.90, 0.90, 0.90), ncol=ncol(y), nrow=nrow(y), byrow=TRUE)
    colours <- matrix("#e9f1e9", nrow(y), ncol(y))
    colours[1:nrow(colours), 1] <- "white"
    tt1 <- ttheme_default(core=list(fg_params=list(hjust = as.vector(hj),
                x = as.vector(x), fontface=c(rep("plain",ncol(y)))), bg_params = list(fill =colours , col="black")))
    tab<-tableGrob(y, rows = NULL, theme = tt1)
    grid.newpage()
    grid.draw(tab)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-27
      • 1970-01-01
      • 1970-01-01
      • 2011-11-18
      • 1970-01-01
      • 2014-09-08
      • 2019-10-16
      • 2016-05-28
      相关资源
      最近更新 更多