具有image()功能的PWM热图

时间:2018-02-27 20:30:32

标签: r bioinformatics

我想使用image()功能,用两种颜色(黑色和白色)绘制热图,但我不知道如何。

有人能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

我们可以使用 fields 包绘制图片,参见示例。

首先,让我们从 seqLogo 包中获取示例PWM数据,并将其转换为矩阵对象:

# source("https://bioconductor.org/biocLite.R")
# biocLite("seqLogo")
library(seqLogo) # bioconductor

# get example matrix
mFile <- system.file("Exfiles/pwm1", package="seqLogo")
m <- read.table(mFile)

plotDat <- as.matrix(m)
plotDat
#       V1  V2  V3  V4  V5  V6  V7  V8
# [1,] 0.0 0.0 0.0 0.3 0.2 0.0 0.0 0.0
# [2,] 0.8 0.2 0.8 0.3 0.4 0.2 0.8 0.2
# [3,] 0.2 0.8 0.2 0.4 0.3 0.8 0.2 0.8
# [4,] 0.0 0.0 0.0 0.0 0.1 0.0 0.0 0.0

现在我们可以使用字段图像功能进行绘图,我们需要指定颜色,注意我们可以使用graphics::image(plotDat)fields::image.plot有更多的绘图自定义选项:

library(fields)

image.plot(plotDat, col = c("black", "white"))

enter image description here