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
• 38,010 points
332 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
• 63,420 points

Related Questions In Others

0 votes
1 answer

Excel Formula Help Conditional Formatting - If A2 =TODAY and B2=Y turn A2 Green. If B2 = N turn A2 RED

Create a conditional format rule on A2 ...READ MORE

answered Dec 29, 2022 in Others by narikkadan
• 63,420 points
349 views
0 votes
1 answer

Lock and unlock cells in Excel based on color in all worksheets

The following should function if you actually ...READ MORE

answered Feb 11, 2023 in Others by Kithuzzz
• 38,010 points
380 views
0 votes
1 answer

How to automatically assign a color to the maximum and minimum values in a set of selected cells in Excel?

See Conditional Formatting, which may be accessed ...READ MORE

answered Apr 7, 2023 in Others by Kithuzzz
• 38,010 points
283 views
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,440 points
559 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
• 63,420 points
988 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
• 63,420 points
592 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
• 63,420 points
1,406 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
• 63,420 points
1,288 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
• 63,420 points
6,874 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
• 63,420 points
580 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