Dambo Dambo - 1 month ago 51
R Question

How to change the color scheme in ggvis?

I would like to change the color palette to two arbitrary HEX colors. How can I do it in the chart below?

hec <- as.data.frame(xtabs(Freq ~ Hair + Eye, HairEyeColor))

hec %>%
ggvis(~Hair, ~Eye, fill = ~Freq) %>%
layer_rects(width = band(), height = band()) %>%
scale_nominal("x", padding = 0, points = FALSE) %>%
scale_nominal("y", padding = 0, points = FALSE)

Answer

You need to set the range in scale_numeric to change the start and end of a continuous fill gradient.

For example, if you wanted a range of red to green you would use

scale_numeric("fill", range = c("red", "green"))