3

我希望在 R 中创建类似于以下类型的不连续热图:

在此处输入图像描述

在此处输入图像描述

我的数据排列如下:

k_e percent time
 ..   ..     ..
 ..   ..     ..

我希望k_e成为 x 轴,percent在 y 轴上并time表示颜色。

我能找到的所有链接都绘制了一个连续矩阵 http://www.r-bloggers.com/ggheat-a-ggplot2-style-heatmap-function/或插值。但我不希望上述任何一种,我想绘制不连续的热图,如上图所示。

4

2 回答 2

3

第二个是十六进制图如果你的 (x,y) 对是唯一的,你可以做一个 xy 图,如果这是你想要的,你可以尝试使用基本 R 绘图函数:

x <- runif(100)
y<-runif(100)
time<-runif(100)

pal <- colorRampPalette(c('white','black'))
#cut creates 10 breaks and classify all the values in the time vector in
#one of the breaks, each of these values is then indexed by a color in the
#pal colorRampPalette.

cols <- pal(10)[as.numeric(cut(time,breaks = 10))]

#plot(x,y) creates the plot, pch sets the symbol to use and col the color 
of the points
plot(x,y,pch=19,col = cols)

使用 ggplot,您还可以尝试:

library(ggplot2)
qplot(x,y,color=time)
于 2015-01-30T12:37:08.377 回答
1

生成数据

d <- data.frame(x=runif(100),y=runif(100),w=runif(100))

使用ggplot2

require(ggplot2)

样本数

以下代码生成一个不连续的热图,其中颜色表示落入垃圾箱的项目数:

ggplot(d,aes(x=x,y=y)) + stat_bin2d(bins=10)

在此处输入图像描述

平均重量

w以下代码创建了一个不连续的热图,其中颜色表示当前 bin 内所有样本的变量平均值。

ggplot(d,aes(x=x,y=y,z=w)) + stat_summary2d(bins=10)

在此处输入图像描述

于 2015-01-30T13:11:42.390 回答