Guest User

Untitled

a guest
Jun 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. # Color the values from one cell along a gradient based upon percentiles
  2. # instead of the values themselves
  3. # Do this for all columns
  4.  
  5. library(formattable)
  6. library(scales)
  7.  
  8. mydf <- data.frame(A = round(runif(10, 0, 100), 0),
  9. B = round(runif(10, 0, 100), 0),
  10. C = round(runif(10, 0, 100), 0),
  11. stringsAsFactors = FALSE)
  12.  
  13.  
  14. do_thing <- function(.x) {
  15. result <- lapply(names(.x), function(n) {
  16. formatter("span",
  17. style = ~ style(color = scales::div_gradient_pal()(ecdf(mydf[,n])(mydf[,n]))))
  18.  
  19. })
  20.  
  21. names(result) <- names(.x)
  22.  
  23. result
  24. }
  25.  
  26. formattable(mydf, do_thing(mydf))
Add Comment
Please, Sign In to add comment