簡體   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