r - "Nested" barplots, with multiple levels of grouping -
how can group bars in barplot third variable?
i achieve in base r, without, example, ggplot2, in this related question. in another related question groups of groups labeled, not (visually) grouped – in example above –, making plot difficult read.
sample data:
groups = c("a", "b") choices = c("orange", "apple", "beer") supergroups = c("fruits", "non-fruits") dat <- data.frame( group = rep(groups, c(93, 94)), choice = factor(c( rep(choices, c(51, 30, 12)), rep(choices, c(47, 29, 18)) ), levels = choices ), supergroup = c( rep(supergroups, c(81, 12)), rep(supergroups, c(76, 18)) ) ) barplot(table(dat), beside = true)
which returns error:
error in barplot.default(table(dat), beside = true) : 'height' must vector or matrix
Comments
Post a Comment