Description Usage Arguments Author(s) References Examples
Alter the data set to fill ggplot2's facet_wrap
by
column rather than row.
1 | fill_by_column(dataframe, fact, ncol = 2)
|
dataframe |
A data.frame object. |
fact |
The factor to be reordered (re-leveled) to fill by column. |
ncol |
Number of columns to make the plot |
jem77bfp (stackoverflow.com) and Tyler Rinker <tyler.rinker@gmail.com>
http://stackoverflow.com/a/12893273/1000343
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.