我的数据集如下:
group ratio
0-0.2 58%
0.2-0.4 68%
0.4-0.6 60%
0.6-0.8 80%
我想在下图中可视化上面的数据集,
如何在R中实现这一点,尤其是在图中添加这些标签,例如68%?
答案 0 :(得分:4)
更可重用的解决方案;
data<-runif(1000)
myLab<-diff(unlist(lapply(seq(0,1,0.2), function(y){sum(data<y)})))*100/length(data)
hist(data,breaks=seq(0,1,0.2), labels =paste0(myLab,"%"), col ="yellow")
答案 1 :(得分:3)
忽略重复非零y轴,这样的事情会起作用:
x <- c(58, 68, 60, 80)
savplot <- barplot(x,space=0,col="yellow",border=NA)
axis(1,at=0:length(x),labels=seq(0,0.8,0.2))
par(xpd=NA)
text(labels=paste0(x,"%"),savplot,x+5,cex=1.5)
par(xpd=TRUE)