r - Fill being ignored with group + facet_wrap in ggplot2 / geom_bar -
i suspect might using group incorrectly here, can't seem understand why fill color getting ignored in example below.
df <- data.frame(a = factor(c(1,1,2,2,1,2,1,2)), b = factor(c(1,2,3,4,5,6,7,2)), c = factor(c(1,2,1,2,1,2,1,2))) p <- ggplot(df, aes(x=b)) + geom_bar(aes(y = ..density.., group = c, fill=a), binwidth = 1) + facet_wrap(~ c) + scale_y_continuous(labels = percent_format()) + scale_color_hue() p any appreciated. in advance, --jt
i think understand plot you're after now. i'd this:
df <- data.frame(a = c(1,1,2,2,1,2,1,2), b = c(1,2,3,4,5,6,7,2), c = c(1,2,1,2,1,2,1,2)) df <- within(df, { f <- 1 / ave(b, list(c), fun=length)}) df[, 1:3] <- lapply(df[, 1:3], as.factor) ggplot(df, aes(x = b)) + geom_bar(stat = "identity", position = "stack", aes(y = f, group = c, fill = a), binwidth = 1) + facet_wrap(~ c) + scale_y_continuous(labels = percent_format()) this gives plot:

Comments
Post a Comment