Entering edit mode
How can I plot only upper triangular portion of a gene by gene correlation matrix with pheatmap package ?
Even if I try to remove lower triangle by: mat[lower.tri(mat)] <- "NA"
it does not work.
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
It probably will work if you remove quotation marks around NA. Also turn off the clustering of rows and columns to see nice triangular plot.
It does work, but I want the rows and columns to be clustered.
Then you have to cluster the data before you assign some values NA. For example assuming that mat is full correlation matrix you can do the following
It's perfect Raivo.
Is there a way to also show dendogram along with heatmap?
I tried
It is a hack but basically you can achieve it like this (starting from full correaltion matrix again)
I tried to perform the code, but I am getting following error. I also tried to look for the error:
Hi,
I am not yet able to figure out that:
test = matrix(rnorm(200), 20, 10) test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3 test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2 test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4 colnames(test) = paste("Test", 1:10, sep = "") rownames(test) = paste("Gene", 1:20, sep = "") mat <- cor(t(test)) o = rownames(mat) hc = hclust(as.dist(1 - mat)) mat = mat[hc$order, hc$order] mat[lower.tri(mat)] = NA mat = mat[o, o] pheatmap(mat, cluster_rows = hc, cluster_cols = hc)
Error in if (cluster_rows) { : argument is not interpretable as logical
In addition: Warning message:
In if (cluster_rows) { :
the condition has length > 1 and only the first element will be used
You have to update your version of pheatmap. This feature of giving clustering as a parameter was introduces fairly recently.
So, I will update it from github.