2013-07-28 35 views
1

我有一個數據集如下里面添加標籤:關於數字

group ratio 
    0-0.2 58% 
0.2-0.4 68% 
0.4-0.6 60% 
0.6-0.8 80% 

我想以可視化的上述數據,如下圖設置,

enter image description here

我怎樣才能在R中實現這一點,特別是在圖中添加這些標籤,例如68%?

+0

不要只爲可視化使用R等你可以用它來生成統計數據(在你的案例中有2步)。 – sgun

回答

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") 

enter image description here

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) 

enter image description here