This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to reassign the orientation of clusters in pheatmap

Hi everyone,

I have a very basic question that I can't get over it :D

I am plotting a heatmap using pheatmap function in R and clustering columns with the option cluster_cols = T. the resulting picture is like below. However, I want the column 1 to be at the right side of the plot, next to gene labels. is there any function in R that allows me to to that? Or does pheatmap has any option for this? this is my code:

ph.breaks <- seq(from = -8.1, to = 12, length.out = 101)
ph.cols <- colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(100)
pdf(paste0(fig_name , "_withLFC_main.pdf"), width = 6.25 , height = 20)

print(pheatmap(t, cluster_cols = T , show_colnames = T,
               fontsize_row = 28 , fontsize_col = 20 , cluster_rows = T, fontsize = 20 , legend = T
               , annotation_legend = T , angle_col = 315 , na_col="#800080" , breaks = ph.breaks)  )
dev.off()
graphics.off()

Thank you in advance.

enter image description here

r pheatmap heatmap

Show us your code please. In the meantime, try this:

# Let's say df is the data object you're plotting using pheatmap(df, ...)
# Try this
pheatmap(df[,4:1], ...)

I tried that, It still results in the same exact plot, Unfortunately,

Thanks, I edited and added my code.

1 answer

This is because your samples are being clustered and the order is dictated by the dendrogram. If you change it to cluster_cols = FALSE you can set the order of the columns.

Thanks a lot! I appreciate it.

Log in to answer this question.