[R] Plot a matrix

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Thu Nov 1 07:55:44 CET 2018


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 using gmail.com> wrote:
>
> Hello!
>
> I need your help to plot my data. I have a file .csv which looks like that:
>
> 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
>
> It is a matrix of distance with in the 1st column and row the days of
> sampling and then the distance values.
> I would like to do a scatterplot of the data with for the y axis the
> distance values and for the x axis the difference between the days of
> sampling (e.g. x = |41442-41540| and y = 0.001).
> Do you know how I could do that with r?
> Thanks in advance for your help.
>
> Best regards,
> Myriam
>
> --
> Myriam Croze
> Post-doctorante
> Division of EcoScience,
> Ewha Womans University
> Seoul, South Korea
>
> Email: myriam.croze07 using gmail.com
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.




More information about the R-help mailing list