[英]Change matrix/raster coordinates on R
I'm a beginner and I have worked a lot on my problem, but I am still stuck... 我是一个初学者,已经为我的问题做了很多工作,但是我仍然陷于困境...
I have a matrix containing values of world temperature. 我有一个包含世界温度值的矩阵。 The size is 360*720.
尺寸为360 * 720。 The values are from -180, -90 (Longitude, latitude) to 180, 90 with a resolution of 0.5.
值从-180,-90(经度,纬度)到180、90,分辨率为0.5。
> head(matrix)
NaN. NaN..1 NaN..2 NaN..3 NaN..4, [...] NaN..718 NaN..719
[1,] Na Na Na Na Na Na
[2,] Na Na Na Na Na Na
[3,] Na Na Na Na Na Na
[4,] Na Na Na Na Na Na
[5,] Na Na Na Na Na Na
[6,] -1.6634 -1.6634 -1.6634 -1.6634 -1.6634 -1.7469
...
This matrix "looks like" a raster. 该矩阵“看起来像”栅格。 My problem is that I don't know how to tell R the matrix resolution.
我的问题是我不知道如何告诉R矩阵分辨率。
If I then rasterise and plot with plot(raster(matrix))
, I get this : http://postimg.org/image/gdnblob07/ Yet, I need the axis to be -180;180 (x) and -90;90 (y) 如果我然后使用
plot(raster(matrix))
化和绘图,则会得到以下信息: http : //postimg.org/image/gdnblob07/然而,我需要将轴设置为-180; 180(x)和-90;。 90(y)
Do you know how I could do? 你知道我该怎么办吗?
Thanks a lot 非常感谢
Using the raster
package is the right intuition but when you instantiate it with just the matrix it doesn't get the extents accurately. 使用
raster
包是正确的直觉,但是当仅使用矩阵实例化raster
包时,它无法准确获取范围。 This will do it: 这样做:
library(raster)
r <- raster(nrow=360,ncol=720,vals=matrix)
plot(r)
raster
will initialize a raster object with (by default), world boundaries. raster
将使用(默认)世界边界初始化栅格对象。 You can optionally specify the coordinate reference system (eg, crs="+proj=longlat +datum=WGS84"), and the extents (ymx, ymn, xmx, xmn). 您可以选择指定坐标参考系统(例如crs =“ + proj = longlat + datum = WGS84”)和范围(ymx,ymn,xmx,xmn)。 cell size is implicit and calculated from the extents and rows/cols.
像元大小是隐式的,并根据范围和行/列计算。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.