繁体   English   中英

具有单元中成员数的R热图

[英]R heatmap with number of members in cell

我有一个用于创建热图的数据集。 问题之一是某些单元格中的成员很少,并且可能存在其他成员未平均的异常值。

为此,我想在单元格中(单元格中央的图)中包括单元格中实际上有多少个示例。

以下是我的热图代码:

library(fields)
library(akima)

x1 <- round(runif(20) * 100,0)
y1 <- round(runif(20) * 100,0)
z1 <- round(runif(20) * 100,0)

s <- interp(x1,y1,z1,
        xo = seq(0,100,20)
        ,yo = seq(0,100,20)
        )

image.plot(s)

有什么建议么?

在计算了单元的角和中心之后,可以使用findIntervaltable来计数观察值。

library(fields)
library(akima)

x1 <- floor(runif(20) * 100)
y1 <- floor(runif(20) * 100)
z1 <- floor(runif(20) * 100)

# Corners of the cells, to count the observations
x0 <- seq(0,100,20)
y0 <- seq(0,100,20)

# Centers of the cells, for the interpolation
x00 <- x0[-length(x0)] + diff(x0) / 2
y00 <- y0[-length(y0)] + diff(y0) / 2

s <- interp(x1,y1,z1, xo=x00, yo=y00)
image.plot(x=x0, y=y0, z=s$z)

counts <- table( 
  findInterval(x1, x0),
  findInterval(y1, y0)
)
# Plot the observations, to check that I have not confused rows and columns
points( x1, y1 )
# Number of observations
text(x=x00[row(counts)], y=y00[col(counts)], labels=counts)

image.plot与计数

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM