图例用列覆盖

时间:2014-07-02 14:59:39

标签: r bar-chart legend

我有一个图例,但它会覆盖条形图中的一列。

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

1 个答案:

答案 0 :(得分:-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


修改 更为独特的方法是在args.legend内使用legend.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