Skip to content
Prev 377197 / 398502 Next

Plot a matrix

Hi Myriam,
This may not be the ideal way to do this, but I think it works:

mcdf<-read.table(text="41540 41540 41442 41599 41709 41823 41806 41837
41898 41848
41442 0.001
41599 0.002 0.001
41709 0.004 0.003 0.003
41823 0.002 0.001 0.002 0.001
41806 0.004 0.004 0.005 0.006 0.005
41837 0.004 0.004 0.005 0.006 0.005 0.001
41898 0.004 0.004 0.005 0.006 0.005 0.001 0.001
41848 0.005 0.004 0.005 0.007 0.005 0.001 0.001 0.001",
fill=TRUE)
nrows<-nrow(mcdf)
ncols<-ncol(mcdf)
mcdf2<-mcdf
for(row in 2:nrows) {
 for(col in 2:ncols) {
  if(!is.na(mcdf2[row,col])) mcdf2[row,col]<-mcdf[row,1]-mcdf[1,col]
 }
}
plot(0,xlim=range(as.numeric(unlist(mcdf2[2:nrows,2:ncols])),na.rm=TRUE),
 ylim=range(as.numeric(unlist(mcdf[2:nrows,2:ncols])),na.rm=TRUE),
 xlab="Difference in days",ylab="Distance",type="n")
for(row in 2:nrows) {
 for(col in 2:ncols) {
  if(!is.na(mcdf2[row,col])) points(mcdf2[row,col],mcdf[row,col])
 }
}

Jim
On Thu, Nov 1, 2018 at 5:21 PM Myriam Croze <myriam.croze07 at gmail.com> wrote: