4

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

为此,我想在单元格中包括(在单元格中心绘制),单元格中实际有多少示例。

以下是我的热图代码:

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)

有什么建议么?

4

1 回答 1

2

在计算单元格的角和中心后,您可以使用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

于 2013-07-30T15:12:08.913 回答