插入不均衡的差距

时间:2015-06-26 14:31:09

标签: r statistics

我有一个如下所示的数据框:

   depth time          temp
1       0    1 -1.620339e-02
2      10    1 -7.018468e-02
3      20    1 -4.392311e-02
4      30    1 -2.344012e-02
5      50    1 -1.817276e-02
6      75    1 -6.413543e-03
7     100    1 -6.547729e-02
...
320   700   20  2.285078e-02

深度变量不均匀,例如:0 10 20 30 50 75 100 125 150 200 250 300 400 500 600 700

我正在尝试创建一个绘图,其中y =深度,x =时间,并且间隙按temp进行插值和着色。如果我这样做:

viz <- ggplot(temp_data, aes(time, depth, z = temp))
viz + geom_tile(aes(fill = temp)) + stat_contour()

它让我接近,但由于深度尺度不均匀,它有大量未开槽数据。我想插入差距,但是我已经用了一段时间了,因为我已经使用了R而且我无法找到实现这一目标的最佳方法。

谢谢 - 非常感谢任何帮助或建议!

1 个答案:

答案 0 :(得分:1)

使用您的样本数据:

library(akima)
library(ggplot2)
interped <- with(temp_data, interp(time, depth, temp))
temp_data_interp <- with(interped, 
    data.frame(time=rep(x, length.out=length(z)), depth=rep(y, each=length(y)), temp=as.vector(z))
)

查看?interp以调整输出x和y值的数量。

如果没有插值,您将得到以下图:

viz <- ggplot(temp_data, aes(time, depth, z = temp))
viz + geom_tile(aes(fill = temp)) + stat_contour()

enter image description here

插值后,你得到:

viz <- ggplot(temp_data_interp, aes(time, depth, z = temp))
viz + geom_tile(aes(fill = temp)) + stat_contour()

enter image description here

相关问题