Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
301 views
in Technique[技术] by (71.8m points)

gridextra - Color background dataframe/datatable with a condition character in r

esiea <- c(1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0)
fesiea <- c("PASS", "FAIL", "FAIL", "PASS", "PASS", 
            "PASS", "FAIL", "PASS", "PASS", "FAIL", "FAIL")
    
dt_essaye <- data.frame(esiea, fesiea)
    
find_cell <- function(table, row, col, name = "core-fg") {
  l <- table$layout
  which(l$t == row & l$l == col & l$name == name)
}

dfc.grob <- gridExtra::tableGrob(as.data.frame(dt_essaye),
                                 theme = ttheme_default(base_size = 10), 
                                 rows = NULL)
c_id = vector()
c_id[1] = 0
     
for(i in 1:nrow(dt_essaye)) {
  c_id[i] = find_cell(dfc.grob, i+1, 2, "core-bg")
  if(c_id[i] == "PASS") {
    dfc.grob$grobs[c_id[i]][[2]][["gp"]] <- gpar(fill = "forestgreen", 
                                                 col = "white")
  } else {i = i}
}
     
grid.draw(dfc.grob)

I would like to color only the column when it's says "PASS" in forestgreen.

question from:https://stackoverflow.com/questions/66061969/color-background-dataframe-datatable-with-a-condition-character-in-r

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...