以下是我简化后的数据:
company <-c(rep(c(rep("company1",4),rep("company2",4),rep("company3",4)),3))
product<-c(rep(c(rep(c("product1","product2","product3","product4"),3)),3))
week<-c( c(rep("w1",12),rep("w2",12),rep("w3",12)))
mydata<-data.frame(company=company,product=product,week=week)
mydata$rank<-c(rep(c(1,3,2,3,2,1,3,2,3,2,1,1),3))
mydata=mydata[mydata$company=="company1",]
同时,我使用的R代码:
ggplot(mydata,aes(x = week,fill = as.factor(rank))) +
geom_bar(position = "fill")+
scale_y_continuous(labels = percent_format())
在条形图中,我想按周、按等级标注百分比。问题在于数据没有等级的百分比。并且这个数据的结构不适合有一个百分比。 (当然,原始数据比示例数据多得多)。有人能教我如何在这个图表中标注百分比吗?