我在R中有一个数据框,类似这样
Score Result
1 1 Pass
2 0.8 Pass
3 1 Pass
4 0.5 Fail
5 0.3 Fail
6 0.2 Fail
根据结果(通过或失败)的值,我想在将数据框写入PDF时显示大拇指或大拇指向下的图像。
我不想使用针织或闪亮。任何帮助将不胜感激。
答案 0 :(得分:2)
您可以在grid.table,
中定义自己的单元格函数d <- read.table(textConnection("Score Result
1 1 Pass
2 0.8 Pass
3 1 Pass
4 0.5 Fail
5 0.3 Fail
6 0.2 Fail"), stringsAsFactors=FALSE)
library(gridExtra)
library(grid)
library(png)
up <- rasterGrob(readPNG("up.png"), height = unit(1,"line"))
down <- rasterGrob(readPNG("down.png"), height = unit(1,"line"))
cell_grob <- function (label, parse = FALSE, col = "black", fontsize = 12, ...)
{
switch(label, "Pass" = up, "Fail" = down,
grid::textGrob(label = label, ...))
}
custom <- ttheme_default(core = list(fg_fun = cell_grob))
grid.newpage()
grid.table(d, theme = custom)