c1 <- c("p2","p3","p1","p2","p1","p3","p4","p4","p4","p1","p1","p2","p2","p3","p4","p2","p1","p4","p3","p3")
c2 <- c(41,146,79,107,131,127,32,88,119,148,32,65,36,23,44,76,100,98,121,104)
df <- data.frame(c1=c1, c2=c2)
我正在尝试在ggplot2中创建一个堆积的条形图,其中x轴的间隔和y轴的计数
概念上是这样
ggplot(df, aes(x=c2.intervals, y=count.c2.occurrences, fill=c1)) + geom_bar()
其中c2.intervals
可能是0-70, 71-100, 100-150
例如,对于间隔0-70
,p1
出现一次,p2
3次,p3
一次,p4
两次。这些将是图中第一个堆积列的计数。
解决此问题的最佳方法是什么?