0

我有一个dt由 204 行和 19 列组成的时间序列(时间、纬度、值)。

我想使用rasterandoceanmap包将我的时间序列绘制为光栅图。

我正在尝试将数据框转换为栅格但有一些问题

这是我的代码:

library(raster)

dt <- t(data.table::data.table(tb))   #tb is the previous matrix with values
rownames(dt) <- tm.mtx    #my time as Dates
colnames(dt) <- cdt    #lat coordinates
dt[is.nan(dt)] <- NA


dt.melt <- reshape2::melt(dt, id=c(row.names(dt)))


spg <- dt.melt
colnames(spg) <- c("x","y","z")
coordinates(spg) <- ~ x + y

它返回这个:

.local(obj, ...) 中的错误:无法从非数字矩阵导出坐标

我知道我必须将日期转换为数字,所以:

rownames(dt) <- tm #vector of time in seconds from "2002-08-15"
dt.melt <- reshape2::melt(dt, id=c(row.names(dt)))
spg <- dt.melt
colnames(spg) <- c("x","y","z")
coordinates(spg) <- ~ x + y
gridded(spg) = T

返回:

建议的最小公差:0.107308

points2grid(points, tolerance, round) 中的错误:维度 1:坐标间隔不是恒定的

从这里我不知道该怎么办。我在下面附上一些部分数据

head(dt)
           -46.4375070233063 -46.4791737000479 -46.5208403767895 -46.5625070535311
2002-08-15         0.1736002         0.1750216         0.1732153         0.1774634
2002-09-15         0.1544965         0.1651486         0.1691601         0.1751704
2002-10-15         0.1882919         0.1835454         0.1881429         0.1941372
2002-11-15         0.2535837         0.2623392         0.2630876         0.2709922
2002-12-15         0.2187145         0.2208886         0.2157844         0.2170794
2003-01-15         0.1413760         0.1334794         0.1383164         0.1370846
           -46.6041737302728 -46.6458404070144 -46.687507083756 -46.7291737604976
2002-08-15         0.1773711         0.1833218        0.1922676         0.1941034
2002-09-15         0.1771452         0.1796460        0.1761335         0.1702302
2002-10-15         0.1968857         0.2063893        0.2040608         0.1979190
2002-11-15         0.2707081         0.2532419        0.2730597         0.2807892
2002-12-15         0.2154748         0.2144032        0.2160844         0.2267726
2003-01-15         0.1385788         0.1351013        0.1375451         0.1544153
           -46.7708404372393 -46.8125071139809 -46.8541737907225 -46.8958404674641
2002-08-15         0.1936037         0.1870466         0.1829850         0.1970123
2002-09-15         0.1650944         0.1764924         0.1801598         0.1772189
2002-10-15         0.1889605         0.1884651         0.1911619         0.1967313
2002-11-15         0.2862864         0.3205168         0.3466025         0.3267133
2002-12-15         0.2262225         0.2184253         0.2562738         0.2705393
2003-01-15         0.2592504         0.3460798         0.4375293         0.5184022
           -46.9375071442058 -46.9791738209474 -47.020840497689 -47.0625071744306
2002-08-15         0.2062590         0.2063133        0.2125093         0.2129866
2002-09-15         0.1775195         0.1759667        0.1642771         0.1685364
2002-10-15         0.2002673         0.1997982        0.1997716         0.1917371
2002-11-15         0.2311774         0.3478559        0.3199840         0.3296006
2002-12-15         0.3308617         0.3285339        0.5459298         0.6657989
2003-01-15         0.6338662         0.6308048        0.5857707         0.4804939
           -47.1041738511723 -47.1458405279139 -47.1875072046555
2002-08-15         0.2157603         0.2188090         0.2243740
2002-09-15         0.1742391         0.1754706         0.1729936
2002-10-15         0.2043249         0.2011236         0.2345921
2002-11-15         0.3316522         0.3430276         0.3336774
2002-12-15         0.6513002         0.5746747         0.4276562
2003-01-15         0.4010864         0.4328661         0.4627818
tm
  [1]         1   2678401   5270401   7948801  10540801  13219201  15897601  18316801
  [9]  20995201  23587201  26265601  28857601  31536001  34214401  36806401  39484801
 [17]  42076801  44755201  47433601  49939201  52617601  55209601  57888001  60480001
 [25]  63158401  65836801  68428801  71107201  73699201  76377601  79056001  81475201
 [33]  84153601  86745601  89424001  92016001  94694401  97372801  99964801 102643201
 [41] 105235201 107913601 110592001 113011201 115689601 118281601 120960001 123552001
 [49] 126230401 128908801 131500801 134179201 136771201 139449601 142128001 144547201
 [57] 147225601 149817601 152496001 155088001 157766401 160444801 163036801 165715201
 [65] 168307201 170985601 173664001 176169601 178848001 181440001 184118401 186710401
 [73] 189388801 192067201 194659201 197337601 199929601 202608001 205286401 207705601
 [81] 210384001 212976000 215654401 218246401 220924801 223603201 226195201 228873601
 [89] 231465601 234144001 236822401 239241601 241920001 244512001 247190401 249782401
 [97] 252460801 255139201 257731201 260409601 263001601 265680001 268358401 270777601
[105] 273456001 276048001 278726401 281318401 283996801 286675201 289267201 291945601
[113] 294537601 297216001 299894401 302400001 305078401 307670401 310348801 312940801
[121] 315619201 318297601 320889601 323568001 326160001 328838401 331516801 333936001
[129] 336614401 339206401 341884801 344476801 347155201 349833601 352425601 355104001
[137] 357696001 360374401 363052801 365472001 368150401 370742401 373420801 376012801
[145] 378691201 381369601 383961601 386640001 389232001 391910401 394588801 397008001
[153] 399686401 402278401 404956801 407548801 410227201 412905601 415497601 418176001
[161] 420768001 423446400 426124800 428630400 431308800 433900800 436579200 439171200
[169] 441849600 444528000 447120000 449798400 452390400 455068400 457747200 460166400
[177] 462844800 465436800 468115200 470707200 473385600 476064000 478656000 481334400
[185] 483926400 486604800 489283200 491702400 494380800 496972800 499651200 502243200
[193] 504921600 507600000 510192000 512870400 515462400 518140800 520819200 523238400
[201] 525916800 528508800 531187200 533779200

数据 http://www.filedropper.com/df

4

0 回答 0