ropensci / iheatmapr

Complex, interactive heatmaps in R
https://docs.ropensci.org/iheatmapr
Other
267 stars 36 forks source link

reverse color scale #20

Open alpreyes opened 6 years ago

alpreyes commented 6 years ago

Is it possible to reverse the color scale in one-color gradients so that the darker color correspond to the to lower values and lighter colors correspond to greater values?

AliciaSchep commented 6 years ago

This is possible, albeit a bit clunky at the moment. The colors argument to functions like main_heatmap and iheatmap can take in a vector of colors instead of a palette name. So you can do something like:

mat <- matrix(rnorm(20), ncol = 5, nrow = 4)  
main_heatmap(mat, colors = rev(RColorBrewer::brewer.pal(3,"Reds"))) 
# Can change 3 to higher number 
# rev function reverses order of the colors
# colors argument also works for iheatmap function

I'll keep this issue open as a note to either: 1) Add more to docs to explain this possibility 2) Possibly add something like a reverse_colorscale option in future

alpreyes commented 6 years ago

Thank you, Alicia. This is greatly appreciated!