Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Scale for min max on color_tile #111

Open
mastoltejr opened this issue Dec 18, 2018 · 2 comments
Open

Custom Scale for min max on color_tile #111

mastoltejr opened this issue Dec 18, 2018 · 2 comments

Comments

@mastoltejr
Copy link

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

@Atrebas
Copy link

Atrebas commented Dec 27, 2018

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))

@monkeywithacupcake
Copy link
Contributor

@mastoltejr - does @Atrebas solution work for your use case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants