[英]How can I introduce a partition between the categories of a stacked bar chart in ggplot2?
除了 @AllanCameron 和 @eipi10 的精彩評論之外,這里是您想要的代碼:
#Data
df <- data.frame(class=c('1st class','1st class','2nd class','2nd class','3rd class','3rd class'),
sex=rep(c('male','female'),3),
n=c(179,143,172,107,499,212))
#Code
ggplot(df,aes(x=class,y=n,fill=sex,label=n))+
geom_bar(stat='identity',color='white',size=1)+
geom_text(color='white',position=position_stack(vjust=0.5),fontface='bold')+
scale_fill_manual(values=c("#cb5e5f", "#0072b1")) +
theme_classic() + theme(legend.position = "b")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.