Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(data.table)
- library(ggplot2)
- # data generation
- colors <- rainbow(20)
- DT <- data.table(x = runif(1e4), grp = sample(LETTERS[1:10], 1e4, TRUE))
- breaks <- seq(0, 1, by = 0.05)
- DT[ , color := colors[findInterval(x, breaks)]]
- ggplot(DT, aes(x)) +
- stat_bin(aes(fill = color), breaks = breaks, show.legend = FALSE) +
- facet_wrap(~grp, 5, 2)
- # percentage
- ggplot(DT, aes(x)) +
- stat_bin(aes(fill = color, y = (..count..)/sum(..count..)),
- breaks = breaks, show.legend = FALSE) +
- facet_wrap(~grp, 5, 2) + labs(y = "Percentage")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement