rOU是一个包含3列250行的矩阵,下图为
matplot(rOU,type =" l",ylim = range(rOU),col = c(" black"," green"," ;红色&#34)
如何为r的每一列写出R中的图例?
谢谢。
答案 0 :(得分:1)
一些可重现的数据
set.seed(1234)
rOU = matrix(rnorm(3*250,0,1),ncol=3),dimnames = list(rep("",250),LETTERS[1:3]))
然后绘制数据
matplot(rOU,type="l", ylim=range(rOU), col=c("black","green","red"), lty = 1:3, pwd = 1)
如果你想将它添加到你可以简单的地图区域:
legend('right',legend = colnames(rOU), col = c('black','green','red'), lty = 1:3, lwd = 1 )
但是你可能不希望图例覆盖情节,所以你可以做的是修改情节的边距,为图例留出空间:
par(mar=c(5,5,2,6))
matplot(rOU,type="l", ylim=range(rOU), col=c("black","green","red"))
legend(280,1,legend = colnames(rOU), col = c('black','green','red'), lty = 1:3, lwd = 1 , xpd = T )