Column labels cropped when using pheatmap

余生颓废 提交于 2019-11-29 11:39:48
Adam Price

I figured this out, hopefully if anyone has this problem in the future it will help.

This happens when you are using the labels_col= argument of pheatmap. In my scenario, which was a RNA-seq project using DESeq2, there was a targets file identifying the samples (columns), but for my column labels I was using a different column so the labels were more understandable, so I used

labels_col=myThing$ThisOtherColumn

The other column, while actually a string containing characters and numbers, for some reason was being read as an integer vector. So the solution was to do

as.character(myThing$ThisOtherColumn)

As long as you give labels_col a character vector it will adjust the columns automatically.

pheatmap uses grid graphics, so base graphics functions like par() is not going have an effect. I find that adjusting arguments cellheight and cellwidth manually can help to adjust the overall size of the heatmap on the page. Or in some way adjusting the margin.

library(pheatmap)
dfr <- as.data.frame(t(data.frame(x=runif(10),y=runif(10),z=runif(10))))
md <- data.frame(cat1=sample(x=letters[1:4],10,replace=T),cat2=sample(x=letters[6:7],10,replace=T))
rownames(md) <- colnames(dfr)
pheatmap(dist(as.data.frame(t(dfr))),annotation_col=md,annotation_row=md)

pheatmap(dist(as.data.frame(t(dfr))),annotation_col=md,annotation_row=md,
         cellheight=15,cellwidth=15)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!