简体   繁体   中英

R: read.table for heatplot

I have the following matrix:

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

which I want to plot as a heatmap.

With the code posted below, I have problems reading the file - the rownames and header are not kept. Plus, I would like that the values are displayed with a % on the heatmap or the 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)

Try this:

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))

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM