Using this small dataset:
df <- structure(list(colour = structure(c(1L, 2L, 1L, 2L), .Label = c("Black",
"White"), class = "factor"), variable = c("A", "A", "B", "B"),
value = c(1, 2, 0.74, 0.85)), row.names = c(NA, -4L), .Names = c("colour",
"variable", "value"), class = "data.frame")
I can easily create a vertical stacked barplot with ggvis
library(ggvis)
df %>%
ggvis(x=~variable, y=~value, fill=~colour) %>%
group_by(colour) %>%
layer_bars()
But I cannot figure out how to have a horizontal stacked barplot. I think I am somehow supposed to use layer_rects
but the best I could get so far was just one group plotted.
df %>%
ggvis(x =~value, y=~variable, fill =~ colour) %>%
group_by(colour) %>%
layer_rects(x2 = 0, height = band())