得到R中的表面图 [英] get a surface plot in R

查看:131
本文介绍了得到R中的表面图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从数据框AAA获取表面图:

I'm trying to obtain a surface plot from data frame AAA:

j     a           m  p       o            f
13929 0.86739583  19 165.83  0.1588727    13.24444
13930 0.63166667  19 178.19  0.6105804    12.68333
13932 0.90212963  17 157.77  0.3345627    12.52222
13933 0.80152778  68 146.19  0.1219885    12.35000
13934 0.75784722  62 134.88  0.1531627    12.36667
13935 0.57763889  66 123.80  0.4093869    12.47500
13936 0.56201389  88 112.87  0.9095722    12.45833
13937 0.51680556  26 102.03  0.8494420    12.37500
13938 0.46093333  28  91.20  0.9153419    12.21111
13939 0.16645833  24  80.30  0.8309784    12.04444
13940 0.15451389  36  69.23  2.2847927    12.15556
13941 0.51347222 134  57.92  2.9551087    12.42500
13942 0.33763889 128  46.31  3.5784096    12.53333
13943 0.12937500  38  34.33  3.7371723    12.47778
13944 0.42760870  63  22.00  4.7831677    12.46667
13945 0.09962121   8   9.36  4.8281897    12.30000
13950 0.97901515  18  57.70  0.0000000    12.15833
13951 0.85333333  14  71.07  0.0000000    12.48333
13952 0.92811594  14  84.28 10.0444672    12.49167
13953 0.84812500  42  97.29  7.8020987    12.51667

我的代码:

require(fields)
fitx <- Tps( AAA[, 4:6], AAA$a)
out.p <- predict.surface(fitx, xy = c(4,5))
plot.surface(out.p, type="p")

但是,它并没有通过.显然,网格不足以表示数据,并且无法获取predict.surface.

However, it doesn't run through. Apparently, the grid is insufficient to represent the data and it's not able to get the predict.surface.

推荐答案

Tps函数中,您的x矩阵为AAA[, 4:6],因此具有三列.

In the Tps function, your x matrix is AAA[, 4:6] and hence has three columns.

但是在predict.surface函数中,您指定了xy = c(4,5).传递给xy参数的值是相对于fitx对象中的矩阵的.由于用于使用predict.surface函数创建fitx的矩阵有三列,因此您不能引用第4列和第5列.相反,原始数据的第4列和第5列.帧AAA对应于fitx的第1列和第2列.

But in the predict.surface function, you specified xy = c(4,5). The values passed to the xyparamter are relative to the matrix in your fitx object. Since the matrix used for creating fitx with the predict.surface function has three columns, you can't refer to the 4th and 5th column. Instead, the columns 4 and 5 of your original data.frame AAA correspond to columns 1 and 2 in fitx.

您不妨尝试:

library(fields)
fitx <- Tps(AAA[, 4:6], AAA$a)
out.p <- predict.surface(fitx, xy = c(1,2)) # Note the different argument passed to `xy`
plot.surface(out.p, type="p")

这篇关于得到R中的表面图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆