My data set dart
is a matrix with dimensions 1981 x 278. The first column contains chromosome numbers from 1 to 21, the second column is the marker names and the third is the distances (CM).
The code below plots the LD decay for one chromosome. I want to repeat the same thing for the 21 chromosomes (looping over them).
Any help or comment will be appreciated.
dart<- read.csv("dartnonaR.csv")
chr1 <- which(dart[, 1] == 1);
mpos <- dart[chr1,2:3 ];
head(mpos);
dart1 <- dart[chr1,];
dim(dart1);
dart2 <- dart1[,-c(1,2,3)];
dart2 <- t(dart2);
r2 <- (cor(dart2))^2;
rownames(r2) <- mpos$MARKERS;
mark <- rownames(r2);
r2a <- r2;
r2v <- NULL;
distance <- NULL;
for( i in 1:144){
for (j in (i+1):145){
r2v <- c(r2v, r2a[i,j])
distance <- c(distance, abs(mpos[mpos$MARKERS == mark[i],2] - mpos[mpos$MARKERS == mark[j],2]) )
cat(i,j,"\n")
}
};
plot(distance, r2v, xlab = "Distance in cM", ylab = "LD in r2");