3

我正在尝试在 R 建议中使用 A 真实热图,但是出现错误:

interp.old(x, y, z, xo = xo, yo = yo, ncp = 0, extrap = extrap,
: x 和 y 的尺度太不相似

在代码行之后:

 s <- interp(x,y,z)

我的数据被构建,期望在黑暗的连续背景中获得像线条一样的彩色热图,并且可以GNUplot使用set pm3d mapset hidden3d. 数据对应y于给定时间 ( x) 内的分子生产模型 ( ),出现频率用 表示z。它看起来像这样:

1.000000000000e+00  1e-8    0

1.000000000000e+00  5e-8    0

1.000000000000e+00  1e-7    5

1.000000000000e+00  5e-7    0

1.000000000000e+00  1e-6    0

1.000000000000e+00  5e-6    0

1.000000000000e+00  1e-5    0

1.000000000000e+00  5e-5    0

1.000000000000e+00  1e-4    0

1.000000000000e+00  5e-4    0

1.000000000000e+00  1e-3    0

1.000000000000e+00  5e-3    0

1.000000000000e+00  1e-2    0

1.000000000000e+00  5e-2    0

1.000000000000e+00  1e-1    0

1.000000000000e+00  5e-1    0

1.000000000000e+00  1e+1    0

1.000000000000e+00  5e+1    0

1.000000000000e+00  1e+2    0

1.000000000000e+00  5e+2    0

1.000000000000e+00  1e+3    0

1.000000000000e+00  5e+3    0

1.000000000000e+00  1e+4    0

1.000000000000e+00  5e+4    0

1.000000000000e+00  1e+5    0

1.000000000000e+00  5e+5    0

1.000000000000e+00  1e+6    0

1.000000000000e+00  5e+6    0

1.000000000000e+00  1e+7    0

1.000000000000e+00  5e+7    0

1.000000000000e+00  1e+8    0

1.000000000000e+00  5e+8    0

2.000000000000e+00  1e-8    0

2.000000000000e+00  5e-8    0

2.000000000000e+00  1e-7    0

2.000000000000e+00  5e-7    5

2.000000000000e+00  1e-6    0

2.000000000000e+00  5e-6    0

2.000000000000e+00  1e-5    0

2.000000000000e+00  5e-5    0

2.000000000000e+00  1e-4    0

2.000000000000e+00  5e-4    0

2.000000000000e+00  1e-3    0

2.000000000000e+00  5e-3    0

2.000000000000e+00  1e-2    0

2.000000000000e+00  5e-2    0

2.000000000000e+00  1e-1    0

2.000000000000e+00  5e-1    0

2.000000000000e+00  1e+1    0

2.000000000000e+00  5e+1    0

2.000000000000e+00  1e+2    0

2.000000000000e+00  5e+2    0

2.000000000000e+00  1e+3    0

2.000000000000e+00  5e+3    0

2.000000000000e+00  1e+4    0

2.000000000000e+00  5e+4    0

2.000000000000e+00  1e+5    0

2.000000000000e+00  5e+5    0

2.000000000000e+00  1e+6    0

2.000000000000e+00  5e+6    0

2.000000000000e+00  1e+7    0

2.000000000000e+00  5e+7    0

2.000000000000e+00  1e+8    0

2.000000000000e+00  5e+8    0

3.000000000000e+00  1e-8    0

3.000000000000e+00  5e-8    0

3.000000000000e+00  1e-7    0

3.000000000000e+00  5e-7    0

3.000000000000e+00  1e-6    5

3.000000000000e+00  5e-6    0

3.000000000000e+00  1e-5    0

3.000000000000e+00  5e-5    0

3.000000000000e+00  1e-4    0

3.000000000000e+00  5e-4    0

3.000000000000e+00  1e-3    0

3.000000000000e+00  5e-3    0

3.000000000000e+00  1e-2    0

3.000000000000e+00  5e-2    0

3.000000000000e+00  1e-1    0

3.000000000000e+00  5e-1    0

3.000000000000e+00  1e+1    0

3.000000000000e+00  5e+1    0

3.000000000000e+00  1e+2    0

3.000000000000e+00  5e+2    0

3.000000000000e+00  1e+3    0

3.000000000000e+00  5e+3    0

3.000000000000e+00  1e+4    0

3.000000000000e+00  5e+4    0

3.000000000000e+00  1e+5    0

3.000000000000e+00  5e+5    0

3.000000000000e+00  1e+6    0

3.000000000000e+00  5e+6    0

3.000000000000e+00  1e+7    0

3.000000000000e+00  5e+7    0

3.000000000000e+00  1e+8    0

3.000000000000e+00  5e+8    0

4.000000000000e+00  1e-8    0

4.000000000000e+00  5e-8    0

4.000000000000e+00  1e-7    0

4.000000000000e+00  5e-7    0

4.000000000000e+00  1e-6    0

4.000000000000e+00  5e-6    5

4.000000000000e+00  1e-5    0

4.000000000000e+00  5e-5    0

4.000000000000e+00  1e-4    0

4.000000000000e+00  5e-4    0

4.000000000000e+00  1e-3    0

4.000000000000e+00  5e-3    0

4.000000000000e+00  1e-2    0

4.000000000000e+00  5e-2    0

4.000000000000e+00  1e-1    0

4.000000000000e+00  5e-1    0

4.000000000000e+00  1e+1    0

4.000000000000e+00  5e+1    0

4.000000000000e+00  1e+2    0

4.000000000000e+00  5e+2    0

4.000000000000e+00  1e+3    0

4.000000000000e+00  5e+3    0

4.000000000000e+00  1e+4    0

4.000000000000e+00  5e+4    0

4.000000000000e+00  1e+5    0

4.000000000000e+00  5e+5    0

4.000000000000e+00  1e+6    0

4.000000000000e+00  5e+6    0

4.000000000000e+00  1e+7    0

4.000000000000e+00  5e+7    0

4.000000000000e+00  1e+8    0

4.000000000000e+00  5e+8    0

第一个建议给了我一些丑陋的结果,类似于最初在R 中的 A true heat map 中获得的结果,这是一个带有一些水平线的图,其中充满了不同灰度色调的点。第二个似乎崩溃了。我从中得到了这条消息:

>Traceback:
1: .Fortran("idsfft", as.integer(1), as.integer(ncp), as.integer(n),     as.double(x),  as.double(y), as.double(z), as.integer(nx),     as.integer(ny), x = as.double(xo), y = as.double(yo), z = zo,     integer((31 + ncp) * n + nx * ny), double(5 * n), misso = as.logical(misso),     PACKAGE = "akima")
2: interp.old(x, y, z, xo = xo, yo = yo, ncp = 0, extrap = extrap,     duplicate = duplicate, dupfun = dupfun)
3: interp(x, y, z)

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace

我只是包含了更多数据以防万一。我以这种方式调用数据框中的列:

coso <- read.table("/home/libertad/mygraphs/two/two_1_90/coso.txt", header = FALSE,sep = "\t")

>x <-coso[[1]]

>y <-coso[[2]]

这是我在 GNUplot 中的图表之一,我希望用 R 得到更好的图表。

4

1 回答 1

5

建议的解决方案

用于scale()将 x 和 y 转换为可比较的比例。

模拟

fields在您的问题中使用该软件包:

library(akima) 
library(fields) 

x <- rnorm(20, 4, 3)
y <- rnorm(20, 5e-5, 1e-5)
x <- scale(x) # comment out these two lines 
y <- scale(y) # to reproduce your error
z <- rnorm(20)

s <- interp(x,y,z)
image.plot(s)

使用ggplot2,改编自我在这里的其他答案

library(akima) 
library(ggplot2) 

x <- rnorm(20, 4, 3)
y <- rnorm(20, 5e-5, 1e-5)
x <- scale(x) # comment out these two lines 
y <- scale(y) # to reproduce your error
z <- rnorm(20)

t. <- interp(x,y,z)
t.df <- data.frame(t.)

gt <- data.frame( expand.grid(X1=t.$x, 
                              X2=t.$y), 
                  z=c(t.$z), 
                  value=cut(c(t.$z), 
                            breaks=seq(min(z),max(z),0.25)))

p <- ggplot(gt) + 
    geom_tile(aes(X1,X2,fill=value)) + 
    geom_contour(aes(x=X1,y=X2,z=z), colour="black") 
p

更正轴标签

在另一个问题中,还描述了在重新缩放之前用原始数据的正确值标记轴的解决方案。这目前仅适用于ggplot.

于 2012-06-02T08:41:44.767 回答