2014-07-02 368 views
0

我有一個圖例,但它覆蓋了barplot中的一列。圖例覆蓋

BOD<-matrix(c(2846,2397,4408,3563,2001,1713,4137,3197,136,107,307,203), 
      nrow = 3, byrow = T) 

colnames(BOD)<-c("BOD","BOD lọc","COD","COD lọc") 
DT <- barplot(BOD, 
       main="Do Thi BOD", 
       legend=c("<5 Nam","5-10 Nam",">10 Nam"), 
       beside = T) 

enter image description here

+0

閱讀'barplot'並注意'args.legend'參數。按照「?legend」的鏈接,並閱讀如何指定圖例的繪製位置。 – joran

回答

-1

你可以使用legend("topleft", …)(假設你的問題是定位圖例)。

BOD<-matrix(c(2846,2397,4408,3563,2001,1713,4137,3197,136,107,307,203), 
      nrow = 3, byrow = T) 

colnames(BOD)<-c("BOD","BOD lọc","COD","COD lọc") 
DT <- barplot(BOD,main="Do Thi BOD",beside = T) 
legend("topleft",legend=c("<5 Nam","5-10 Nam",">10 Nam")) 

這裏是我的陰謀: Plot with legend topleft


編輯: 這樣做的更idiomic方式將使用args.legendlegend.textbarplot本身,如

DT <- barplot(BOD, 
       main="Do Thi BOD", 
       legend.text = c("<5 Nam","5-10 Nam",">10 Nam"), 
       args.legend = list(x = "topleft"), 
       beside = T) 

enter image description here

+0

你能解決我的代碼? – user3798177

+0

非常感謝你!但它失敗 – user3798177

+0

對我來說,它不會失敗。你至少應該給出一個錯誤信息。另外,圖例幫助爲您提供了更多信息。 – mrub