【问题标题】:How to make a heatmap in R with xyz dissimilar data如何在 R 中使用 xyz 不同的数据制作热图
【发布时间】:2012-07-06 00:04:01
【问题描述】:

我正在尝试使用 A true heat map in R 建议,但是我收到错误:

interp.old 中的错误(x, y, z, xo = xo, yo = yo, ncp = 0, extrap = extrap,
: x 和 y 的尺度太不一样了

代码行之后:

 s <- interp(x,y,z)

我的数据被构建为期望在黑暗的连续背景中获得像线条一样的彩色热图,并且使用set pm3d mapset hidden3dGNUplot 中工作。数据对应于给定时间 (x) 内的分子生产模型 (y),出现频率由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

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

>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

>x <-coso[[1]]

>y <-coso[[2]]

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

【问题讨论】:

    标签: r graph gnuplot heatmap


    【解决方案1】:

    建议的解决方案

    使用 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,改编自my other answer here

    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
    

    更正轴标签

    在另一个问题中,在重新缩放之前还为labeling the axes with the correct values of the original data 描述了解决方案。目前这只适用于ggplot

    【讨论】:

    • 我对高登的建议有些问题。我将它们包含在我原来的问题中。
    猜你喜欢
    • 1970-01-01
    • 2011-10-02
    • 2017-10-15
    • 2017-09-03
    • 1970-01-01
    • 1970-01-01
    • 2015-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多