使用网格表拆分列名称

问题描述 投票:0回答:1

我想用grid.table生成格式化表格。这就是我所做的:

library(grid)
d <- head(iris, 3)
colnames(d) <- c("A very long colname", "Sepal Width",  "Petal Length", "Petal Width",  "Species")
grid.table(d, rows=NULL,theme=ttheme_minimal(
  colhead=list(fg_params=list(col="white",fontface=4L),
               bg_params=list(fill="#1bb600"))
))

enter image description here

这是期望的结果(名称列分为两行):

enter image description here

我怎样才能做到这一点?

r datagrid
1个回答
0
投票

您必须重命名行,指定要在部件之间使用\n拆分名称的部件:

library(grid)
d <- head(iris, 3)
colnames(d) <- c("A very\nlong colname", "Sepal\nWidth",  "Petal\nLength", "Petal\nWidth",  "Species")
grid.table(d, rows=NULL,theme=ttheme_minimal(
  colhead=list(fg_params=list(col="white",fontface=4L),
               bg_params=list(fill="#1bb600")), 
  core
))

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.