formattable
formattable copied to clipboard
Custom Scale for min max on color_tile
Hello, I have a column of numbers c(5474, 6284, 6585, 3877, etc) and I want to use the color_tile function to color them proportionate between the range of c(3000, 7000) rather than the default which is used c(min(x) = 3877, max(x) = 6585. Is there any way to do this? Thanks
You can do something like this:
library(formattable)
customRange = c(-50, 35) # custom min / max values
colors = csscolor(gradient(as.numeric(c(customRange, mtcars$mpg)), "white", "pink"))
colors = colors[-(1:2)] ## remove colors for min/max
fmt = formatter("span",
style = function(x){
style(display = "block",
padding = "0 4px",
`border-radius` = "4px",
`background-color` = colors
)})
formattable(mtcars, list(mpg = fmt))
@mastoltejr - does @Atrebas solution work for your use case?