R Setting breakpoints in color gradient in gt-package

53 views Asked by At

I have a dataframe of 2 columns with numbers of different ranges. I want to create a table now, via gt-table Package and color the cells of both columns according to its values.

I would like to have a viridis to magma colorscheme with white for the 0 values. The problem is that there are very high peaks like 1700, or 800 while most other values are between -60 and 500. So for the negative values a simple gradient would be enough, but for the positive values I need more colors and also setting maybe setting a special color for the very high values?

Can somebody please give me an example? My gt tables always seem to have the same colors.

pal = col_numeric("viridis", domain = c(), na.color = "#808080", 
                             alpha = FALSE, reverse = FALSE)

gt(test) %>%
  data_color(columns = c(1,2),
           colors = pal)

enter image description here

   structure(list(Delta_p = c(-19.98, 51.22, NA, 57.61, -17.01, 
    27.76, NA, 43.7, 25.75, NA, NA, 28.72, NA, 52.07, 45.12, NA, 
    -41.56, -16.81, 14.35, -20.09, -35.17, NA, 23.91, 54.09, NA, 
    NA, 10.53, NA, 28.97, 36.76, -11.25, 48.61, 99.01, -20, 137.5, 
    NA, 29.19, 26.71, -29.74, -18, 57.66, -41.91, 25.5, 29.01, 12.47, 
    NA, 22.19, -52.42, 19.01, 32.71, 43.39, NA, 123.88, 76.71, 45.96, 
    105.85, 47.71, 51.72, NA, 43.7, -38.04, -25.05, 45.96, NA, 71.93, 
    12.77, NA, -33.59, 577.78, 52.2, 24.44, 27.06, 127.27, -35.53, 
    -21.34, NA, 8.33, 22.46, 27.65, 93.1, 37.87, 58.9, -19.67, -25.53, 
    -24.35, 27.21, NA, -57.4, 16.62, 16.48, 14.71, 24.81, -30.33, 
    40.79, 45.02, 70.13, 68.65, 29.6, 13.28, -11.87), Delta_n = c(32.25, 
    NA, -20.49, 43.61, -22.97, 26.87, 46.58, 28.69, 46.56, 94.12, 
    36.67, 96.05, 50.15, 59.35, 24.95, 47.93, NA, NA, 28.26, 59.56, 
    -17.03, 89.47, -26.11, 35.5, 29.76, 69.09, NA, 27.75, -13.47, 
    43.58, NA, 72.22, 52.28, -24.95, NA, -16.4, 65.49, 51.58, 23.94, 
    -19.1, -21.1, 70.97, NA, -26.96, 22.39, -21.74, 20.47, 27.33, 
    41.44, 24.69, 32.33, 68.16, -23.7, NA, -19.9, NA, NA, -19.9, 
    -19.71, 24.91, NA, 24.85, 30.38, 23.72, 89.67, NA, 69.05, NA, 
    NA, 35.07, 37.39, -32.13, 90.91, 28.08, -13.34, 24.23, -20.49, 
    NA, -15.04, 100.86, NA, NA, -18.1, 16.85, NA, 18.38, 276.83, 
    22.82, 36, -9.78, NA, 20.83, NA, 21.54, 52.36, -23.95, NA, 12.74, 
    NA, 20.36)), row.names = c(2117L, 2609L, 200L, 340L, 1576L, 1353L, 
    1710L, 832L, 1530L, 895L, 1980L, 92L, 273L, 884L, 1784L, 452L, 
    2610L, 2109L, 733L, 261L, 2277L, 1447L, 1588L, 1803L, 1989L, 
    275L, 2192L, 2500L, 1876L, 2077L, 1637L, 2536L, 971L, 2596L, 
    283L, 360L, 1316L, 83L, 1310L, 2000L, 529L, 2201L, 2189L, 563L, 
    1486L, 487L, 2046L, 97L, 98L, 1554L, 1769L, 2318L, 782L, 1845L, 
    196L, 802L, 2414L, 198L, 1712L, 2220L, 1201L, 2480L, 2491L, 2237L, 
    2539L, 2207L, 2537L, 1432L, 73L, 730L, 2477L, 582L, 1209L, 2291L, 
    2336L, 737L, 1853L, 2409L, 1281L, 426L, 1054L, 1205L, 566L, 1299L, 
    129L, 2069L, 948L, 846L, 1723L, 1148L, 208L, 490L, 2269L, 6L, 
    1187L, 1184L, 2091L, 2143L, 1439L, 1703L), class = "data.frame")
0

There are 0 answers