我想在R
中绘制如下所示的条形图这是从像
这样的数据框创建的X1 X2 X3
No No No
Yes No Yes
Yes Yes Yes
36% = total no of yes in X1
64% = (total no of yes in X2+total no of yes in X3)
如果问题不明确,请与我联系并发表评论。
答案 0 :(得分:1)
获得它的直接方法是绘制多边形并添加文本。
Proportion1 = 0.36
Proportion2 = 0.64
plot(NULL, xlim=c(0,1), ylim=c(0,1), xaxt="n", yaxt="n",
xlab="", ylab="", bty='n')
polygon(c(0,Proportion1,Proportion1,0), c(0.4,0.4,0.6,0.6), col="blue")
polygon(c(Proportion1,1,1,Proportion1), c(0.4,0.4,0.6,0.6), col="green")
text(c(Proportion1/2, Proportion2/2 + Proportion1), c(0.5,0.5),
c(paste0(100*Proportion1, "%"), paste0(100*Proportion2, "%")),
col="white", cex=1.5)