R:read.table 用于热图

R: read.table for heatplot

我有以下矩阵:

row genome1 genome2 genome3
genome1 100 99.99 98.88
genome2 99.99 100 NA
genome3 98.88 NA 100

我想绘制成热图。

使用下面发布的代码,我在读取文件时遇到问题 - 行名和 header 未保留。 另外,我希望这些值在热图或 NA.

上显示为 %
ani <-read.table(file="matrix", header=T, sep="\t", dec=".", row.names=1)
anim<-as.matrix(as.data.frame(lapply(ani, as.numeric)))
library(gplots)
my_palette <- colorRampPalette(c("red", "yellow", "green"))(n = 299)
heatmap.2(anim, notecol="black", density.info="none", trace="none", col=my_palette, cellnote=anim)

试试这个:

ani <- read.table(text='
row genome1 genome2 genome3
genome1 100 99.99 98.88
genome2 99.99 100 NA
genome3 98.88 NA 100
', header=T, row.names=1, quote="")

anim <- as.matrix(ani)
library(gplots)
my_palette <- colorRampPalette(c("red", "yellow", "green"))(n = 299)
heatmap.2(anim, notecol="black", density.info="none", trace="none", 
          col=my_palette, cellnote=anim, margins=c(10,10))