【发布时间】:2020-09-04 13:01:02
【问题描述】:
df <- data.frame(sd = c('05AP.U1 1 ','05AP.U2 1','07RT.U1 1'),percentpl = c(50,40,80),percentan = c(50,60,20),count = c(100,100,100))
sd percentpl percentan count
1 05AP.U1 50 50 100
9 03KM.U2 40 60 100
12 07RT.U1 80 20 100
是否可以仅在df 的基础上绘制堆叠百分比条形图。我用ggplot 尝试过,但在fill 变量上失败了。
ggplot(df, aes(fill=`percentpl`+`percentan`, y=count, x=`sd`)) +
geom_bar(position="fill", stat="identity")+ theme(axis.text = element_text(angle = 90))
我还看到过其他几个类似的问题R ggplot2 stacked barplot, percent on y axis, counts in barsAdd percentage labels to a stacked barplot
【问题讨论】: