简体   繁体   中英

Heatmap.2 controlling axis in R

I am using heatmap.2 function from the gplots library to plot a heatmap. I managed to create the heatmap but have few questions regarding the axis. I wanted the heatmap to show only selected values of the axis. Please refer the heatmap imaged attached below. I would like to know how can I only display points like X76.100, X176.200, X276.300 etc on X axis and Y76.100, Y176.200, Y276.300 on Y axis, while hiding the other points on both axis.

Please let me know if the question needs more clarification.

Code that I have used so far:

   library(gplots)     
   file=read.table("Heatfile25.txt", sep="\t", header=TRUE, row.names=1)
   file[is.na(file)]<-0
   data_matrix<-as.matrix(file)
   heatmap.2(data_matrix, scale="none",dendrogram="none", col=grey(seq(1,0,-0.01)),      
     trace="none", Rowv=NA, Colv=NA, main="PB2 VS PB1")

Thanks 在此处输入图片说明

By going from matrix to data.frame for your input data you can easily use filter statements to select the relevant rows and columns. Let DF be your data.frame :

columnKeeps <- c("X76.100", "X176.200", "X276.300")
DFfiltered <- DF[,(names(DF) %in% columnKeeps)]

rowKeeps <- c("Y76.100", "Y176.200", "Y276.300")
DFfiltered <- DFfiltered [(rownames(DFfiltered) %in% rowKeeps),]

Cannot test right now so I may have swapped column and row but you should manage :)

See Drop data frame columns by name for more details

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