[当使用stat =“ identity”的geom_bar时,y轴最大值是所有值的总和。在此示例中,我希望y轴最大值为100,而不是300,并且堆叠的条形图显示每个复制的条形图的比例。有人知道我该怎么做吗?
dat = data.frame(sample = c(rep(1, 12),
rep(2, 9),
rep(3, 6)),
category = c(rep(c("A", "B", "C"), each = 4),
rep(c("A", "B", "C"), each = 3),
rep(c("A", "B", "C"), each = 2)),
replicate = c(rep(c("a", "b", "c", "d"), 3),
rep(c("a", "b", "c"), 3),
rep(c("a", "b"), 3)),
value = c(rep(25, 12),
rep(c(25, 25, 50), 3),
rep(50, 6))
)
ggplot(dat,
aes(x = sample, y = value)) +
geom_bar(aes(fill = replicate),
stat = "identity")