There is no proper 'z' matrix specified in contour ()

I'm trying to make a simple contour plot of R, but I get the following error: "no proper 'z' matrix specified"

. Below is my code:

r=read.table("test.dat")
dim(r)
## [1] 56  3

x=matrix(unlist(r[,3]),ncol=112,byrow=T)
dim(x)
## [1] 1 11

image((1:nrow(x))-56,(1:ncol(x))-56,x)
contour((1:nrow(x))-56,(1:ncol(x))-56,x , add=TRUE)

## Error in contour.default((1:nrow(x)) - 56,
##   (1:ncol(x)) - 56, x, add = TRUE) :
##     no proper 'z' matrix specified

      

Can anyone help me where I am making the mistake.

+3


source to share


1 answer


The code contour.default

(which you can print by typing the function name at the prompt in the R console) contains the line:

 if (!is.matrix(z) || 
     nrow(z) <= 1L || 
     ncol(z) <= 1L) 
     stop("no proper 'z' matrix specified")

      



... in other words, contour()

refuses to try to process a matrix that has only one row or only one column. Is this really what you set out to conceive? If so, perhaps you can explain the context in more detail?

0


source







All Articles