2014-06-14 182 views
1

我已經在R中繪製了直方圖,並在垂直間隔中使用abline()標記了分位數。但是,我想繪製一個圖例,顯示分位數的相應值以及分位數間隔本身。圖例動態填充

當前的圖例幾乎就在那裏,你可以看到如果你運行下面的示例代碼。但我似乎無法成功地將圖例間隔與其相應的值和彩色線符號對齊。我試圖用data.frame()來達到這個目的,但沒有成功。

任何提示或建議將非常感激。

x<-1:100 
quantiles_x<-quantile(x) 
hist(x) 
abline(v=quantiles_x, col=c("blue", "green","red","yellow","black")) 
legend('topright', legend=c(names(quantiles_x), levels(factor(quantiles_x))), lwd=1, col=c("blue","green","red","yellow","black")) 
+0

嘗試在這裏http://stats.stackexchange.com/ – Mihai

+2

@Mihai,這個問題是在正確的位置,刪除您的評論 – rawr

回答

0

這樣的事情?

x<-1:100 
quantiles_x<-quantile(x) 
hist(x) 
abline(v=quantiles_x, col=c("blue", "green","red","yellow","black")) 
labels <- paste(names(quantiles_x), "[",quantiles_x,"]") 
legend('topright', legend=labels, lwd=1, 
     col=c("blue","green","red","yellow","black"))