如何更改ggvis中的配色方案?

How to change the color scheme in ggvis?

我想将调色板更改为两种任意的十六进制颜色。我怎样才能在下面的图表中做到这一点?

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)

您需要在 scale_numeric 中设置 range 以更改连续填充渐变的开始和结束。

例如,如果您想要从红色到绿色的范围,您可以使用

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