本文介绍了如何使用xyz不相似的数据在R中生成热图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正尝试使用 R中的真正热图建议,但我得到的错误: 后面的代码行: s pre> 我的数据是在黑暗的连续背景下构建的,希望获得像线一样的彩色热图,并且可以在 GNUplot 使用设置pm3d map 和设置hidden3d 。数据对应于分子生产模型( 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.0000000 00000e + 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.000000000000 e + 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.000000000000 e + 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中真实的热图,它是一些在不同的灰度色调中包含一些水平线的点。第二个似乎崩溃了。我收到了这条消息: > Traceback: 1:.Fortran(idsfft,as。整数(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,整数((31 + ncp)* n + nx * ny),double(5 * n) as.logical(misso),PACKAGE =akima) 2:interp.old(x,y,z,xo = xo,yo = yo,ncp = 0,extrap = extrap,duplicate = duplicate,dupfun = 3:interp(x,y,z) 可能的操作: 1:abort(如果启用了核心转储) 2:正常R退出 3:退出R而不保存工作区 4:退出R保存工作区 我这样调用数据框中的列: > x< -coso [[1]] > y< -coso [[2]] 这是我在GNUplot中的一个图表,我预计会用R获得更好的图表。解决方案 建议的解决方案 使用 scale()来转换x和y使用字段 $ b 模拟 >包在你的问题: 库(akima)库(字段) $ b $ (20,4,3)y x y< - scale(y)#来重现你的错误z -norm(20) s 图像。情节 使用 ggplot2 ,改编自 library(akima) library(ggplot2)$ (20,4,3)y x y< - scale(y)#来重现你的错误z 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), (a)(x1,x2,fill = value)bs = bs(min(z),max(z),0.25))) p geom_tile )+ geom_contour(aes(x = X1,y = X2,z = z),color =black)p 校正轴标签 另一个问题,解决方案也描述为在重新缩放前使用正确的原始数据值标记轴。目前只适用于 ggplot 。 I am trying to use the A true heat map in R suggestions, however I get the error:after the code line: s <- interp(x,y,z)My data was constructed expecting to get coloured heat-map like lines in a dark continuous background, and works in GNUplot using set pm3d map and set hidden3d. The data corresponds to a model of molecules production (y) in a given time (x) with the frequency of appearance denoted by z. It looks like this:1.000000000000e+00 1e-8 01.000000000000e+00 5e-8 01.000000000000e+00 1e-7 51.000000000000e+00 5e-7 01.000000000000e+00 1e-6 01.000000000000e+00 5e-6 01.000000000000e+00 1e-5 01.000000000000e+00 5e-5 01.000000000000e+00 1e-4 01.000000000000e+00 5e-4 01.000000000000e+00 1e-3 01.000000000000e+00 5e-3 01.000000000000e+00 1e-2 01.000000000000e+00 5e-2 01.000000000000e+00 1e-1 01.000000000000e+00 5e-1 01.000000000000e+00 1e+1 01.000000000000e+00 5e+1 01.000000000000e+00 1e+2 01.000000000000e+00 5e+2 01.000000000000e+00 1e+3 01.000000000000e+00 5e+3 01.000000000000e+00 1e+4 01.000000000000e+00 5e+4 01.000000000000e+00 1e+5 01.000000000000e+00 5e+5 01.000000000000e+00 1e+6 01.000000000000e+00 5e+6 01.000000000000e+00 1e+7 01.000000000000e+00 5e+7 01.000000000000e+00 1e+8 01.000000000000e+00 5e+8 02.000000000000e+00 1e-8 02.000000000000e+00 5e-8 02.000000000000e+00 1e-7 02.000000000000e+00 5e-7 52.000000000000e+00 1e-6 02.000000000000e+00 5e-6 02.000000000000e+00 1e-5 02.000000000000e+00 5e-5 02.000000000000e+00 1e-4 02.000000000000e+00 5e-4 02.000000000000e+00 1e-3 02.000000000000e+00 5e-3 02.000000000000e+00 1e-2 02.000000000000e+00 5e-2 02.000000000000e+00 1e-1 02.000000000000e+00 5e-1 02.000000000000e+00 1e+1 02.000000000000e+00 5e+1 02.000000000000e+00 1e+2 02.000000000000e+00 5e+2 02.000000000000e+00 1e+3 02.000000000000e+00 5e+3 02.000000000000e+00 1e+4 02.000000000000e+00 5e+4 02.000000000000e+00 1e+5 02.000000000000e+00 5e+5 02.000000000000e+00 1e+6 02.000000000000e+00 5e+6 02.000000000000e+00 1e+7 02.000000000000e+00 5e+7 02.000000000000e+00 1e+8 02.000000000000e+00 5e+8 03.000000000000e+00 1e-8 03.000000000000e+00 5e-8 03.000000000000e+00 1e-7 03.000000000000e+00 5e-7 03.000000000000e+00 1e-6 53.000000000000e+00 5e-6 03.000000000000e+00 1e-5 03.000000000000e+00 5e-5 03.000000000000e+00 1e-4 03.000000000000e+00 5e-4 03.000000000000e+00 1e-3 03.000000000000e+00 5e-3 03.000000000000e+00 1e-2 03.000000000000e+00 5e-2 03.000000000000e+00 1e-1 03.000000000000e+00 5e-1 03.000000000000e+00 1e+1 03.000000000000e+00 5e+1 03.000000000000e+00 1e+2 03.000000000000e+00 5e+2 03.000000000000e+00 1e+3 03.000000000000e+00 5e+3 03.000000000000e+00 1e+4 03.000000000000e+00 5e+4 03.000000000000e+00 1e+5 03.000000000000e+00 5e+5 03.000000000000e+00 1e+6 03.000000000000e+00 5e+6 03.000000000000e+00 1e+7 03.000000000000e+00 5e+7 03.000000000000e+00 1e+8 03.000000000000e+00 5e+8 04.000000000000e+00 1e-8 04.000000000000e+00 5e-8 04.000000000000e+00 1e-7 04.000000000000e+00 5e-7 04.000000000000e+00 1e-6 04.000000000000e+00 5e-6 54.000000000000e+00 1e-5 04.000000000000e+00 5e-5 04.000000000000e+00 1e-4 04.000000000000e+00 5e-4 04.000000000000e+00 1e-3 04.000000000000e+00 5e-3 04.000000000000e+00 1e-2 04.000000000000e+00 5e-2 04.000000000000e+00 1e-1 04.000000000000e+00 5e-1 04.000000000000e+00 1e+1 04.000000000000e+00 5e+1 04.000000000000e+00 1e+2 04.000000000000e+00 5e+2 04.000000000000e+00 1e+3 04.000000000000e+00 5e+3 04.000000000000e+00 1e+4 04.000000000000e+00 5e+4 04.000000000000e+00 1e+5 04.000000000000e+00 5e+5 04.000000000000e+00 1e+6 04.000000000000e+00 5e+6 04.000000000000e+00 1e+7 04.000000000000e+00 5e+7 04.000000000000e+00 1e+8 04.000000000000e+00 5e+8 0The first suggestion gave me some ugly results similar the ones obtained at first in A true heat map in R which is a plot with some horizontal lines full of dots in different gray-scale tones. The second seems to crash. I got this message from it:>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 exit3: exit R without saving workspace4: exit R saving workspaceI just included more data in case it is helpful.I am calling the columns from the data frame this way:>x <-coso[[1]]>y <-coso[[2]]This is one of my graphs in GNUplot, I expected to get nicer ones with R. 解决方案 Suggested SolutionUse scale() to transform x and y to comparable scales.SimulationUsing the fields package as in your question: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 errorz <- rnorm(20)s <- interp(x,y,z)image.plot(s)Using ggplot2, adapted from 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 errorz <- 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") pCorrecting the Axis LabelsIn another question, the solution is also described for labeling the axes with the correct values of the original data before the re-scaling. This currently only applies to ggplot. 这篇关于如何使用xyz不相似的数据在R中生成热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-21 04:31