Can someone please help me with adding percentages to the following barplot?
library(ggplot2)
library(dplyr)
n <- 10000
test <- data.frame(value = sample(1:3, size = n, replace = TRUE),
grp = sample(c("A", "B", "C"), size = n, replace = TRUE),
item = sample(c("Item1", "Item2", "Item3", "Item4", "Item5", "Item6"), size = n, replace = TRUE)) %>%
mutate(value = as.factor(value))
test %>%
ggplot(aes(x = grp, fill = value, group = value)) +
geom_bar(position = 'fill') +
facet_wrap(item ~., ncol = 2) +
coord_flip() +
scale_fill_manual(values = c("green", "yellow", "red"))