Ggvis histogram - color selection
I am using the Kaggle train ' dataset .
It contains 891 lines. The column I am using is ~ Survived. This column contains the values ββof the coefficients "0" and "1".
I have plotted two values ββusing the following lines of code:
train %>% ggvis(~Survived, fill = ~Survived) %>%
layer_bars()
The result looks like this:
I would like to give the bar for the values ββ"0" red and the bar for the values ββ"1" green.
Can anyone help me?
Thanks in advance.
+3
source to share
2 answers
You are looking for ?scale_nominal
. Scaling is different from ggplot2
- there are only three scales .
library(ggvis)
set.seed(0)
dat <- data.frame(Survived = factor(sample(0:1, 50, rep=T)))
dat %>% ggvis(~Survived, fill=~Survived) %>%
layer_bars() %>%
scale_nominal("fill", range = c("red", "green"))
+3
source to share