问题
I have a file containing an nxn matrix of numeric values with a header row and column containing labels.
I want to produce a contour plot of the values with R (2.14.x) so I am loading in the matrix like so:
mat <- as.matrix(read.table("myfile", row.names=1, sep=",", header=TRUE))
and then attempting to produce a contour plot by:
contour(rownames(mat), colnames(mat), mat)
but I get the error:
Error in r[i1] - r[-length(r):-(length(r) - lag + 1L)] :
non-numeric argument to binary operator
An example matrix that produces the problem contains:
,1,2,3
1,827786,672544,622597
2,674201,651413,533766
3,626531,533179,489844
What's going wrong and how do I fix it? I'm very new to R so I might be doing something stupid here. Any help appreciated.
回答1:
D'oh. Must've misread some documentation on the way - contour(mat)
works fine.
I thought from docs like http://wiki.cbr.washington.edu/qerm/index.php/R/Contour_Plots that I needed to split out the x,y,z.
来源:https://stackoverflow.com/questions/13218541/how-to-produce-contour-plot-in-r-from-matrix