[R] adding legend to matplot

From: kcchalmers <kris4ya_at_gmail.com>
Date: Mon, 02 May 2011 04:58:26 -0700 (PDT)


Hi all, I am new to R programming and I was trying to write a simple code in order to plot my data. The problem is that I am not able to insert a legend corresponding to each column of the data matrix. Please can someone help me out. How can i directly get the legend relating to each data curve.

This is the code I had written:

matrix<-read.table(file="PNPLA.txt",
header=TRUE,
sep="\t",
row.names=1
)

a<-matrix[1:6]

c1<-a[,1]/a[28,1]
c2<-a[,2]/a[28,2]
c3<-a[,3]/a[28,3]
c4<-a[,4]/a[28,4]
c5<-a[,5]/a[28,5]
c6<-a[,6]/a[28,6]

mat<-cbind(c1,c2,c3,c4,c5,c6)

x1<-mat[,1]/a[,1]
x2<-mat[,2]/a[,1]
x3<-mat[,3]/a[,1]
x4<-mat[,4]/a[,1]
x5<-mat[,5]/a[,1]
x6<-mat[,6]/a[,1]

final<-cbind(x1,x2,x3,x4,x5,x6)
matplot(final,type="l")
tfin<-t(final)
colnames(tfin)<-c("PC26","PC28","PC28:02","PC30","PC32","PC3201","PC3202","PC34",
"PC3401","PC3402","PC3404","PC36","PC3601","PC3602","PC3604","PC3606","PC38","PC3804","PC3806","PC40","PC4002","PC4006","PC4008","PC42","PC44","SM21")

matplot(tfin,pch = 1:25, type =
"o",lty=20,lwd=1.9,xlab="Time",ylab="PCmix/SM21:00 ratio")

--
View this message in context: http://r.789695.n4.nabble.com/adding-legend-to-matplot-tp3489844p3489844.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Thu 05 May 2011 - 06:25:06 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 05 May 2011 - 07:00:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive