简体   繁体   中英

How can I delete column names in heatmap.2 in R?

I've built a great heatmap.2 in R but I am trying to remove the column names at the bottom of the heatmap because they are illegible. I am not able to delete the column names.

I've tried doing labCol = NULL and nothing seems to happen. Additionally, colCol = "white" also doesn't work. Any suggestions?

data<-read.csv("Symptoms Only.csv",row.names=1)

data$Subject_type<-gsub("0","Contact",data$Subject_type)
data$Subject_type<-gsub("1","Survivor",data$Subject_type)
data$Gender<-gsub("0","Male",data$Gender)
data$Gender<-gsub("1","Female",data$Gender)

condition_colors <- unlist(lapply(data$Subject_type,function(x){
  if(grepl('Contact',x)) '#FFC0CB'
  else if(grepl('Survivor',x)) '#808080'
  }))

condition_colors

colnames(data)
data<-data[-c(1:3)]
colnames(data)
data<-t(data)

data<-as.matrix(data)

x<-data

z <- heat.clust(x,
                scaledim="column",
                zlim=c(-3,3),
                zlim_select = c("dend","outdata"),
                reorder=c("column","row"),
                distfun  = function(x) as.dist(1-cor(t(x))), 
                hclustfun= function(x) hclust(x, method="ward.D"),
                scalefun = scale)

heatmap.2(z$data,
          Rowv=z$Rowv,
          Colv=z$Colv,
          trace="none",
          scale="none",
          symbreaks = TRUE,
          srtCol=90,
          adjCol=c(0.8,1),
          key=FALSE,
          dendrogram = "both",
          lhei=c(1,5),
          cexRow = 1.1,
          margins=c(4,7),
          labCol = NULL,
          xlab="complete",
          ColSideColors = condition_colors,
          col=rev(colorRampPalette(brewer.pal(10, "RdBu"))(256)),
)```

The image is base R plot, so setting xaxt="n" will remove column names. You would set the column names to empty strings, but maybe not so advisable.

library(gplots)
data(mtcars)
# correct solution
heatmap.2(x,xaxt="n")
# not so good
colnames(x) = rep("",ncol(x))
heatmap.2(x)

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