Hi everyone. The function image() seems not to be correctly plotting some matrices that I give it. (IÂ’m using R 2.1.1) The following code creates a matrix (denoted x) with 1500 rows and 3 columns, with all entries 0 or 1, and then plots the image of this matrix. cc=runif(n=1500,min=0.1,max=1.2) ccc=ceiling(cc-1) dd=runif(n=1500,min=0.1,max=1.2) ddd=ceiling(dd-1) ee=runif(n=1500,min=0.1,max=1.2) eee=ceiling(ee-1) x=matrix(data=c(ccc,ddd,eee),nrow=1500) image(x) ..where the first column in x (vector ccc) is depicted horizontally along the bottom of the image. However, when I overplot the non-zero elements of the vectors ccc, ddd and eee onto their respective horizontal positions on the image,.. points(seq(0,1,1/(1500-1)),(ccc)^-1*0) points(seq(0,1,1/(1500-1)),(ddd)^-1*0.5) points(seq(0,1,1/(1500-1)),(eee)^-1*1) Ââ€Â¦the locations of the 1Â’s in image do not always match the locations of the 1Â’s in ccc,ddd, and eee (although they are mostly correct). Do other people find this problem?? I've tried with other matrices, and the results only seem in error when the matrix is large, say with more than 1000 rows. Cheers, Gareth Davies
possible bug in image() ??
3 messages · Gareth Davies, vincent@7d4.com, Uwe Ligges
Gareth Davies a Âécrit :
Hi everyone. The function image() seems not to be correctly plotting some matrices that I give it. (IÂ’m using R 2.1.1) ..where the first column in x (vector ccc) is depicted horizontally along the bottom of the image.
Hello,
here's a way to have an image according the usual view.
timage = function(M)
{
M1 = M;
for (i in 1:nrow(M)) M1[i,] = M[nrow(M)-i+1,];
image(t(M1));
}
hih
I guess what you see is the limited resolution of your screen rather
than a bug in R.
Try to produce a reliably image, e.g. some pdf file:
pdf("test.pdf")
cc=runif(n=1500,min=0.1,max=1.2)
ccc=ceiling(cc-1)
dd=runif(n=1500,min=0.1,max=1.2)
ddd=ceiling(dd-1)
ee=runif(n=1500,min=0.1,max=1.2)
eee=ceiling(ee-1)
x=matrix(data=c(ccc,ddd,eee),nrow=1500)
image(x)
points(seq(0,1,1/(1500-1)),(ccc)^-1*0, pch=".")
points(seq(0,1,1/(1500-1)),(ddd)^-1*0.5, pch=".")
points(seq(0,1,1/(1500-1)),(eee)^-1*1, pch=".")
dev.off()
and zoom in now ....
Uwe Ligges
Gareth Davies wrote:
Hi everyone. The function image() seems not to be correctly plotting some matrices that I give it. (IÂ’m using R 2.1.1) The following code creates a matrix (denoted x) with 1500 rows and 3 columns, with all entries 0 or 1, and then plots the image of this matrix. cc=runif(n=1500,min=0.1,max=1.2) ccc=ceiling(cc-1) dd=runif(n=1500,min=0.1,max=1.2) ddd=ceiling(dd-1) ee=runif(n=1500,min=0.1,max=1.2) eee=ceiling(ee-1) x=matrix(data=c(ccc,ddd,eee),nrow=1500) image(x) ..where the first column in x (vector ccc) is depicted horizontally along the bottom of the image. However, when I overplot the non-zero elements of the vectors ccc, ddd and eee onto their respective horizontal positions on the image,.. points(seq(0,1,1/(1500-1)),(ccc)^-1*0) points(seq(0,1,1/(1500-1)),(ddd)^-1*0.5) points(seq(0,1,1/(1500-1)),(eee)^-1*1) Ââ€Â¦the locations of the 1Â’s in image do not always match the locations of the 1Â’s in ccc,ddd, and eee (although they are mostly correct). Do other people find this problem?? I've tried with other matrices, and the results only seem in error when the matrix is large, say with more than 1000 rows. Cheers, Gareth Davies
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html