R - 具有两个数据集之间相关性的世界等高线图
我有两个数据集 A 和 B,我想找到相关性并绘制等高线图。
A只是一个简单的向量,有230个流数据。
B是一系列日期下的复杂海面温度(SST)数据。在每个日期,SST 都有一个 360 行 * 180 列记录温度的矩阵。
向量A(230个数据)是:
Houlgrave_flow_1981_2000 = window(Houlgrave_flow_average, start = as.Date("1981-11-15"),end = as.Date("2000-12-15"))
Houlgrave_SF_1981_2000 = coredata(Houlgrave_flow_1981_2000)
矩阵B的维度如下所示,我只使用1到230。
> dim(ssta_sst)
[1] 360 180 362
我寻找相关性的想法如下。
z_correlation = cor(Houlgrave_SF_SST_1981_2000,ssta_sst[c(181:360, 1:180),,i])
尝试一下,i=1。但是,它不起作用。错误消息显示:
"Error in cor(Houlgrave_SF_SST_1981_2000, ssta_sst[c(181:360, 1:180), , :
incompatible dimensions.".
另外,这是我的等高线图代码,
require(maps)
par(ask=TRUE)
for (i in 1:230) {
maps::map(database="world", fill=TRUE, col="light blue")
maps::map.axes()
contour(x=lon_sst, y=lat_sst, z=cor(Houlgrave_SF_1981_2000,ssta_sst[c(181:360, 1:180),,i]), zlim=c(-3,3), add=TRUE)
title(paste("Year: ", year_sst[i], ", Month: ", month_sst[i]))
}
我想我只需要修改等高线代码下的 z 即可。是否需要将每个A的数据重新定义为360*180的数据矩阵?
I have two data sets A and B and i wanna to find the correlation and plot the contour map.
A is just a simple vector with 230 stream flow data.
B is a complicated sea surface temperature(SST) data under a series date. On each date, the SST has a matrix of 360row *180columns of recorded temperatures.
The vector A (230 data) is :
Houlgrave_flow_1981_2000 = window(Houlgrave_flow_average, start = as.Date("1981-11-15"),end = as.Date("2000-12-15"))
Houlgrave_SF_1981_2000 = coredata(Houlgrave_flow_1981_2000)
The dimension of matrix B is shown below and i only use from 1 to 230.
> dim(ssta_sst)
[1] 360 180 362
My idea for finding correlation is below.
z_correlation = cor(Houlgrave_SF_SST_1981_2000,ssta_sst[c(181:360, 1:180),,i])
Try, i=1. However, it doesn't work.The error message says:
"Error in cor(Houlgrave_SF_SST_1981_2000, ssta_sst[c(181:360, 1:180), , :
incompatible dimensions.".
Also, this is my contour map code,
require(maps)
par(ask=TRUE)
for (i in 1:230) {
maps::map(database="world", fill=TRUE, col="light blue")
maps::map.axes()
contour(x=lon_sst, y=lat_sst, z=cor(Houlgrave_SF_1981_2000,ssta_sst[c(181:360, 1:180),,i]), zlim=c(-3,3), add=TRUE)
title(paste("Year: ", year_sst[i], ", Month: ", month_sst[i]))
}
I think i just need to modify z under contour code. Is it necessary to redefine each A's data as a 360*180 data matrix?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解这个问题,你有一个时间序列,即一个其索引可以解释为时间的向量,以及一个3维数组,其索引可以解释为时间和位置。
对于每个位置,您可以使用
apply
u,在下面的代码中)之间的相关性>。If I understand the problem correctly, you have a time series, i.e., a vector whose index can be interpreted as time, and a 3-dimensional array, whose indices can be interpreted as time and position.
For each position, you can compute the correlation between your "flow" time series and the "temperature" time series (
u
, in the code below) for that position, usingapply
.