Reputation: 135
I have a data frame in R, something like this
Score Result
1 1 Pass
2 0.8 Pass
3 1 Pass
4 0.5 Fail
5 0.3 Fail
6 0.2 Fail
Depending upon the value of Result (pass or fail), I would like to display thumbs-up or thumbs-down image when I write the data frame to the PDF.
I don't want to use knitr or shiny. Any help would be appreciated.
Upvotes: 0
Views: 2005
Reputation: 77096
you could define your own cell function in 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)
Upvotes: 2