Imitate Excel style gradient color effect red yellow green in gt data color

0 votes

With code and sample data below, I plot a 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))
  )

enter image description here

Next step I attempted to achieve an approximately same color effect as the following plot, which I have done by the simply selecting the default 3-color scale: red, yellow, green from the Format Style drop-down list in Excel.

enter image description here

Does someone knows the values of the following hex color codes or other R's color palette could achieve same effect? Thanks.

enter image description here

Update: I obtain the similar color codes: "#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))
  )

enter image description here

Dec 28, 2022 in Others by Kithuzzz
• 28,700 points
57 views

1 answer to this question.

0 votes

The similar color palette: 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))
  )

Out:

enter image description here

answered Dec 28, 2022 by narikkadan
• 53,160 points

Related Questions In Others

0 votes
1 answer
0 votes
1 answer

How to use hexadecimal color strings in Flutter?

Hi@akhtar, In Flutter the Color class only accepts integers as parameters, or there ...READ MORE

answered Jul 24, 2020 in Others by MD
• 95,420 points
363 views
0 votes
1 answer

Error cannot provide both a color and a decoration in Flutter container.

Hi@akhtar, The color and decoration arguments cannot both be supplied, since it ...READ MORE

answered Jul 29, 2020 in Others by MD
• 95,420 points
3,333 views
0 votes
1 answer

How to change the background color of AppBar in Flutter?

Hi@akhtar, You can add backgroundColor keyword in your ...READ MORE

answered Aug 12, 2020 in Others by MD
• 95,420 points
1,518 views
0 votes
1 answer

Download multiple excel files linked through urls in R

Try something along the lines of: for (i ...READ MORE

answered Sep 23, 2022 in Others by narikkadan
• 53,160 points
223 views
0 votes
1 answer

Excel, How to split cells by comma delimiter into new cells

The Excel manual method: choose Text to Column ...READ MORE

answered Oct 3, 2022 in Others by narikkadan
• 53,160 points
116 views
0 votes
1 answer

Comparing two Excel files in R and returning different titles

Solution: library(tidyverse) dat <- read_xlsx("Book1.xlsx") dat2 <- read_xlsx("Book2.xlsx") book1_output <- anti_join(dat,dat2, ...READ MORE

answered Oct 14, 2022 in Others by narikkadan
• 53,160 points
267 views
0 votes
1 answer

Conversion of PDF file to Excel in R

I looked at the pdf, and it ...READ MORE

answered Oct 16, 2022 in Others by narikkadan
• 53,160 points
271 views
0 votes
1 answer

What are the RGB and HEX codes of the 3 color conditional format in Excel?

In Excel 2016 at least the colors ...READ MORE

answered Sep 24, 2022 in Others by narikkadan
• 53,160 points
1,140 views
0 votes
1 answer

How to express absolute cell references in Excel R1C1-style formulas?

If the formulas are in Column K ...READ MORE

answered Oct 15, 2022 in Others by narikkadan
• 53,160 points
97 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP