在gt::data_color()中模仿Excel风格的渐变色效果(红、黄、绿)
Imitate Excel style gradient color effect (red, yellow, green) in gt::data_color()
使用下面的代码和示例数据,我绘制了一个 gt table:
df <- structure(list(date = c("2016-1-31", "2016-2-29", "2016-3-31",
"2016-4-30", "2016-5-31", "2016-6-30", "2016-7-31", "2016-8-31",
"2016-9-30"), value1 = c(-15.25, -27.96, 7.53, -5.24, -6.93,
-6.83, -6.47, 13, -10.48), value2 = c(-19.93, -13.76, 20, -11.12,
-0.59, -9.06, 15, 1.66, -1.59)), class = "data.frame", row.names = c(NA,
-9L))
library(gt)
library(tidyverse)
df %>%
gt() %>%
data_color(
columns = value1:value2,
colors = scales::col_numeric(
palette = c(
'red', 'yellow', 'green'),
domain = c(df$value1, df$value2))
)
下一步我尝试实现与下图大致相同的颜色效果,我通过简单地选择默认的 3 色比例来完成:red, yellow, green 来自 Excel.
中格式样式下拉列表
有谁知道以下十六进制颜色代码的值或其他R的调色板可以达到同样的效果吗?谢谢。
更新: 我得到了相似的颜色代码:"#f8696b", "#ffeb84", "#63be7b"
df %>%
gt() %>%
data_color(
columns = value1:value2,
colors = scales::col_numeric(
palette = c(
"#f8696b", "#ffeb84", "#63be7b"),
domain = c(df$value1, df$value2))
)
参考文献:
https://www.excel-easy.com/examples/color-scales.html
What are the RGB codes for the Conditional Formatting 'Styles' in Excel?
相似的调色板:c("#63be7b", "#ffeb84", "#f8696b")
df %>%
gt() %>%
data_color(
columns = value1:value2,
colors = scales::col_numeric(
palette = c(
"#63be7b", "#ffeb84", "#f8696b"),
domain = c(df$value1, df$value2))
)
输出:
使用下面的代码和示例数据,我绘制了一个 gt table:
df <- structure(list(date = c("2016-1-31", "2016-2-29", "2016-3-31",
"2016-4-30", "2016-5-31", "2016-6-30", "2016-7-31", "2016-8-31",
"2016-9-30"), value1 = c(-15.25, -27.96, 7.53, -5.24, -6.93,
-6.83, -6.47, 13, -10.48), value2 = c(-19.93, -13.76, 20, -11.12,
-0.59, -9.06, 15, 1.66, -1.59)), class = "data.frame", row.names = c(NA,
-9L))
library(gt)
library(tidyverse)
df %>%
gt() %>%
data_color(
columns = value1:value2,
colors = scales::col_numeric(
palette = c(
'red', 'yellow', 'green'),
domain = c(df$value1, df$value2))
)
下一步我尝试实现与下图大致相同的颜色效果,我通过简单地选择默认的 3 色比例来完成:red, yellow, green 来自 Excel.
中格式样式下拉列表有谁知道以下十六进制颜色代码的值或其他R的调色板可以达到同样的效果吗?谢谢。
更新: 我得到了相似的颜色代码:"#f8696b", "#ffeb84", "#63be7b"
df %>%
gt() %>%
data_color(
columns = value1:value2,
colors = scales::col_numeric(
palette = c(
"#f8696b", "#ffeb84", "#63be7b"),
domain = c(df$value1, df$value2))
)
参考文献:
https://www.excel-easy.com/examples/color-scales.html
What are the RGB codes for the Conditional Formatting 'Styles' in Excel?
相似的调色板:c("#63be7b", "#ffeb84", "#f8696b")
df %>%
gt() %>%
data_color(
columns = value1:value2,
colors = scales::col_numeric(
palette = c(
"#63be7b", "#ffeb84", "#f8696b"),
domain = c(df$value1, df$value2))
)
输出: