简体   繁体   English

利用R在不规则网格上插值和绘制2d /空间时间序列数据

[英]Interpolation and plotting of 2d/spatial timeseries data on an irregular grid with R

(this is my first post so (i) I hope not to break too many rules and (ii) have to store example plots externally) (这是我的第一篇文章,所以(i)我希望不要破坏太多规则,(ii)必须在外部存储示例图

I would like to visualize irregular gridded timeseries data where the displayed parameter is also a function of a geographical measure like latitude or water depth. 我想要显示不规则网格时间序列数据,其中显示的参数也是纬度或水深等地理测量的函数。 An example data file that contains the date (date), the geographical parameter water depth (dep) and the parameter of interest salinity (sal) and a preliminary scatterplot produced with ggplot2 are stored at our 包含日期(日期),地理参数水深(dep)和感兴趣盐度(sal)参数的示例数据文件以及使用ggplot2生成的初步散点图存储在我们的

owncloud owncloud

password: timeseries 密码:时间序列

The R-code for the ggplot plot is: ggplot图的R代码是:

# Load required packages
library(ggplot2)
library(data.table)
library(colorRamps)
library(scales)

# Import spatial timeseries data
df      <- data.table(read.csv("timeseries_example.csv"))
df$date <- as.POSIXct(strptime(df$date, format="%m/%d/%Y", tz="GMT"))

# Scatterplot with color representing the z parameter

Fig <-
ggplot(data=df, aes(date, dep, col=Sal))+
  geom_point()+
  scale_y_reverse()+
  scale_colour_gradientn(colours = matlab.like2(7), oob=squish)

tiff("./example_timeseries_R_ggplot.tiff", width = 200, height = 100, 
  units =  'mm', res = 300, compression = 'lzw')
Fig
dev.off()

As the data are spaced irregular in space and time, plotting with ggplot's geom_tile() function requires interpolation. 由于数据在空间和时间上间隔不规则,使用ggplot的geom_tile()函数绘图需要插值。

The freely available software ocean data view ( ODV ) enables such interpolation and I would like to reproduce the ODV plot also stored at our owncloud (link above) with R. 免费提供的软件海洋数据视图( ODV )实现了这种插值,我想重现与R一起存储在我们自己的云(上面的链接)中的ODV图。

As this problem is similar to previously solved issues, I tried to interpolate the parameter sal on a finer grid of date and dep with the package akima . 由于这个问题类似于以前解决的问题,我试图在一个更精细的日期网格上插入参数sal,并使用包akima dep。 However, this did not work with the x parameter being a POSIXct object. 但是,这不适用于作为POSIXct对象的x参数。

Does anyone have a solution to this? 有人有解决方案吗?

I've had good luck with the MBA package: 我对MBA套餐好运:

# Load required packages
library(ggplot2)
library(lubridate)
library(reshape2)
library(colorRamps)
library(scales)
library(MBA)

# Import spatial timeseries data
df      <- read.csv("timeseries_example.csv")
df$date <- as.POSIXct(strptime(df$date, format="%m/%d/%Y", tz="GMT"))
df$date <- decimal_date(df$date)

mba <- mba.surf(df[,c('date', 'dep', 'Sal')], 100, 100)
dimnames(mba$xyz.est$z) <- list(mba$xyz.est$x, mba$xyz.est$y)
df3 <- melt(mba$xyz.est$z, varnames = c('date', 'depth'), value.name = 'salinity')

Fig <-
  ggplot(data=df3, aes(date, depth))+
  geom_raster(aes(fill = salinity), interpolate = F, hjust = 0.5, vjust = 0.5) +
  geom_contour(aes(z = salinity)) + 
  geom_point(data = df, aes(date, dep), colour = 'white') +
  scale_y_reverse() +
  scale_fill_gradientn(colours = matlab.like2(7))
Fig

轮廓图

There are some anomalies that you may be able to clean up with the with the interpolation settings. 使用插值设置可以清除一些异常情况。 I just used the default. 我刚刚使用了默认值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM