简体   繁体   English

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

[英]R heatmap with number of members in cell

I have a data set I'm using to create a heatmap. 我有一个用于创建热图的数据集。 One of the issues is that some cells have very few members in them and can have outliers that aren't averaged out by other members. 问题之一是某些单元格中的成员很少,并且可能存在其他成员未平均的异常值。

To this end I'd like to include in the cell (plot in the center of the cells), how many examples are actually in the cell. 为此,我想在单元格中(单元格中央的图)中包括单元格中实际上有多少个示例。

Below is my code for the heatmap: 以下是我的热图代码:

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)

Any suggestions? 有什么建议么?

After computing both the corners and centers of the cells, you can use findInterval and table to count the observations. 在计算了单元的角和中心之后,可以使用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