NMF包绘制热图

KJY / 2018-12-30


NMF包绘制热图

1. 数据和模型

library(NMF)

# random data that follow an 3-rank NMF model (with quite some noise: sd=2)
X <- syntheticNMF(100, 3, 20, noise=2)
# row annotations and covariates
n <- nrow(X)
d <- rnorm(n)
e <- unlist(mapply(rep, c('X', 'Y', 'Z'), 10))
e <- c(e, rep(NA, n-length(e)))
rdata <- data.frame(Var=d, Type=e)
# column annotations and covariates
p <- ncol(X)
a <- sample(c('alpha', 'beta', 'gamma'), p, replace=TRUE)
c <- rnorm(p)
# gather them in a data.frame
covariates <- data.frame(a, X$pData, c)

查看下生成的注释数据:

head(rdata)
##           Var Type
## 1  0.82619529    X
## 2  0.90408091    X
## 3  0.06740537    X
## 4  0.86202089    X
## 5  1.23288876    X
## 6 -0.26067514    X
head(covariates)
##       a Group           c
## 1 gamma     1 -1.01664768
## 2 alpha     1  1.24316990
## 3 gamma     1  0.40491717
## 4 gamma     1 -0.16624575
## 5  beta     1 -0.09481199
## 6 alpha     1  1.71309355

这里X实际是一个矩阵,rdata是行注释,covariates是列注释。

2. 绘图

par(mfrow = c(1, 2))
aheatmap(X, annCol = covariates, annRow = X$fData)
aheatmap(X)

最后一次修改于 2018-12-30