问题描述
我有一个文件,其中包含nxn个数字值矩阵,并且标题行和列包含标签.
I have a file containing an nxn matrix of numeric values with a header row and column containing labels.
我想用R(2.14.x)生成值的等高线图,因此我像这样加载矩阵:
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)
但是我得到了错误:
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
出了什么问题,我该如何解决?我是R的新手,所以我可能在这里做一些愚蠢的事情.任何帮助表示赞赏.
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.
推荐答案
D'oh.一定是在途中误读了一些文档-contour(mat)
正常工作.
D'oh. Must've misread some documentation on the way - contour(mat)
works fine.
我从 http://wiki.cbr.washington之类的文档中想到.edu/qerm/index.php/R/Contour_Plots ,我需要将x,y,z分开.
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.
这篇关于如何从矩阵生成R中的等高线图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!