The following code provides a wonderful stacked bar chart
cls.grp <- gl(n=4,k=20,labels=c("group a","group b","group c", "group d"))
ser <- sample(x=c("neg","pos"),size=80,replace=TRUE, prob=c(30,70))
syrclia <- data.frame(cls.grp,ser)
ggplot(syrclia, aes(cls.grp, fill=ser))+ geom_bar()
I was expecting that with geom_text or stat_summary I would be able to label the percentage who were negative in each group and put it on the corresponding bar. I have tried many permutations and cannot get it to work. I have even tried manually entering the percentages and forcing the labels where I want them but it does not work. It expects 80 labels and I only want to give four that are negative or perhaps 8 (if one includes the labels for the percentage that are positive).
Do I really have to make an aggregated data frame of my syrclia and plot that?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…