绘制三维图的热图 [英] plot a heatmap with a third dimension

查看:118
本文介绍了绘制三维图的热图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制一个这样的热图

I would like to plot a heatmap like this

我知道如何在R中做普通的热图,但是不确定如何引入3D组件.我考虑过只使用3D条形图,但是我不确定如何有条件地设置条形颜色.有人可以推荐一种工具来做这样的事情吗? 另一个示例是此处

I know how to do a normal heatmap in R but am unsure how the 3D component can be introduced. I thought about just using a 3d bar chart but then I am not sure how to conditionally set the bar colour. Can somebody recommend a tool to do something like this? Another example would be here

但是这里没有根据热图颜色进行着色.

but there it is not coloured according to the heatmap colours.

这也可以称为3D直方图.有没有办法在R中产生这样的数字(其中框的最高点由1变量给出,而颜色格式由另一个变量表示?),例如

This might go also by the name of 3D histogram. Is there a way to produce such a figure in R (where the hight of the boxes is given by 1 variable and the colour formatting indicated by another ?) like here

我对JTT解决方案的问题是,我需要能够独立于VA Deaths变量为3D条着色.我有一个2D热图(已经为每个3D条设置了颜色).然后,栏的高度由另一个变量设置.这意味着颜色与高度无关.

My problem with JTT solution is that I would need to be able to colour the 3D Bars independently of the VA Deaths variable. I have a 2D heatmap (which do already set the colours for each 3D bar). The height of the bar is then set by another variable. This means the colour is not related to the height.

推荐答案

3D条形图可能是一种解决方法.您可能要测试的packageExtra软件包中有一个panel.3dbars().有关更多示例,请参见函数的帮助页面,但这是从帮助页面上的示例之一修改而来的一个示例:

3D barchart might be a way to go. There's panel.3dbars() in the package latticeExtra that you might want to test. See the function's help page for more examples, but here's one example modified from one of the examples on the help page:

library(latticeExtra)
# A function generating colors
cols<-function(n) {
   colorRampPalette(c("#FFC0CB", "#CC0000"))(20)                                 # 20 distinct colors
}
# The plot
cloud(VADeaths, panel.3d.cloud = panel.3dbars, col="white",                      # white borders for bars
  xbase = 1, ybase = 1, zlim = c(0, max(VADeaths)),                              # No space around the bars
  scales = list(arrows = FALSE, just = "right"), xlab = NULL, ylab = NULL,
  col.facet = level.colors(VADeaths, at = do.breaks(range(VADeaths), 20),        
                           col.regions = cols,                                   # color ramp for filling the bars
                           colors = TRUE),
  colorkey = list(col = cols, at = do.breaks(range(VADeaths), 20)),
  screen = list(z = 65, x = -65))                                                # Adjust tilting

结果类似于:

请注意,要绘制的数据需要转换为矩阵才能起作用.如果从X * Y网格进行测量,其中Z是测量强度,则应该很容易实现.此处的功能(例如level.colors())会根据数据范围自动确定颜色,但您也可以在绘制之前自行生成颜色.

Note that the data to be plotted needs to be turned into a matrix for this to work. If you have measurement from X*Y grid, where Z is the intensity of the measurement, this should be rather straightforward to pull off. The functions here (e.g., level.colors()) automatically decides the color according to the data range, but you can also generate the colors yourself, before plotting.

这篇关于绘制三维图的热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆