# NOT RUN {
library(ggplot2); library(reshape2)
dat <- aggregate(cbind(vs, am, gear, cyl) ~ carb, mtcars, sum)
dat$carb <- factor(dat$carb, rev(dat$carb[order(rowSums(dat[, -1]))]))
mdat <- melt(dat)
ggplot(mdat, aes(x = variable)) +
geom_bar(stat="count", aes(fill=variable, weight = value)) +
facet_wrap(~carb, ncol = 2) + coord_flip()
ggplot(fill_by_column(mdat, "carb"), aes(x = variable)) +
geom_bar(stat="count", aes(fill=variable, weight = value)) +
facet_wrap(~carb, ncol = 2) + coord_flip()
ggplot(fill_by_column(mdat, "carb", 3), aes(x = variable)) +
geom_bar(stat="count", aes(fill=variable, weight = value)) +
facet_wrap(~carb, ncol = 3) + coord_flip()
# }
Run the code above in your browser using DataLab