首页 > 解决方案 > gt 测距列颜色填充

问题描述

这个问题来自这篇文章

如何将红色和绿色的颜色范围从灰色到红色以及从灰色到绿色?我无法应用颜色范围。

有部分解决方案

library(gt)
library(tidyverse)

logistic_pattern <- function(...) {
  args <- list(...)
  x <- args[[1]]
  thresholds <- args[[2]]
  zeros <- numeric(length(x))
  
  #sigma for normalizacion. 
  # maybe uniform sigma <- (pmax - pmin)/sqrt(12)
  sigma <- 0.2
  
  y <- 1/(1+exp(-(x - thresholds)/sigma))
  
  y
  
}
gt(df) %>% 
  tab_style(
    style = cell_fill(color = "gray85"),
    locations = cells_body(
      columns = c(name, performance),
      rows = between(logistic_pattern(value, threshold), 0.45, 0.55)
    )
  ) %>% 
  tab_style(
    style = cell_fill(
      # color = scales::col_bin(.$threshold, domain = colfunc(10))
      color = "red"
    ),
    locations = cells_body(
      columns = c(name, performance),
      rows = logistic_pattern(value, threshold) < 0.45
    )
  ) %>% 
  tab_style(
    style = cell_fill(
      color = "green"
    ),
    locations = cells_body(
      columns = c(name, performance),
      rows = logistic_pattern(value, threshold) > 0.55
    )
  ) 

我评论了一次失败的尝试,但它不喜欢 R,因为它们的尺寸。

# colfunc <- colfunc <- colorRampPalette(c("red", "gray85", "green"))
# color = scales::col_bin(.$threshold, domain = colfunc(10))

阴谋

标签: rcolorsgt

解决方案


推荐阅读