0
$\begingroup$

I want to plot a heat map in header I have the average of gene expression validated in lab for each sample

dput(heat[1:5,1:5])

structure(c(3.05574677859363, -0.451189292623471, -0.398066832453666, 
-0.456927931251448, -0.393418432279742, -0.270234667496526, -0.451189292623471, 
-0.398066832453666, -0.456927931251448, -0.393418432279742, -0.270234667496526, 
-0.451189292623471, -0.398066832453666, -0.456927931251448, -0.393418432279742, 
-0.270234667496526, -0.451189292623471, -0.398066832453666, 2.0338091136055, 
-0.393418432279742, -0.270234667496526, 1.76078923919148, 1.96896026174603, 
1.97960246116808, -0.393418432279742), .Dim = c(5L, 5L), .Dimnames = list(
    c("hsa-miR-548b-5p", "hsa-miR-181c-5p", "hsa-miR-181d-5p", 
    "hsa-miR-125a-3p", "hsa-miR-4286"), c("30566-001", "30566-002", 
    "30566-003", "30566-004", "30566-005")))


dput(m[1:5,c(2,7)])

structure(list(HealthStatus = c("Healthy", "Healthy", "Healthy", 
"Healthy", "Healthy"), Average = c(108.915677, 103.148873, 40.3359607, 
88.4329528, 87.7756577)), row.names = c("30566-001", "30566-002", 
"30566-003", "30566-004", "30566-005"), class = "data.frame")


pheatmap(heat, cluster_rows=T, show_rownames=T,
         cluster_cols=FALSE, annotation_col=m[,c(2,7)],
         annotation_colors=annot_colors)

How I can order average in a descending way? enter image description here

$\endgroup$
0

1 Answer 1

4
$\begingroup$

If you order your matrix/data.frame you can sort your columns by decreasing "Average", e.g.

library(pheatmap)

heat <- structure(c(3.05574677859363, -0.451189292623471, -0.398066832453666, 
                    -0.456927931251448, -0.393418432279742, -0.270234667496526, -0.451189292623471, 
                    -0.398066832453666, -0.456927931251448, -0.393418432279742, -0.270234667496526, 
                    -0.451189292623471, -0.398066832453666, -0.456927931251448, -0.393418432279742, 
                    -0.270234667496526, -0.451189292623471, -0.398066832453666, 2.0338091136055, 
                    -0.393418432279742, -0.270234667496526, 1.76078923919148, 1.96896026174603, 
                    1.97960246116808, -0.393418432279742), .Dim = c(5L, 5L), .Dimnames = list(
                      c("hsa-miR-548b-5p", "hsa-miR-181c-5p", "hsa-miR-181d-5p", 
                        "hsa-miR-125a-3p", "hsa-miR-4286"), c("30566-001", "30566-002", 
                                                              "30566-003", "30566-004", "30566-005")))

m <- structure(list(HealthStatus = c("Healthy", "Healthy", "Healthy", 
                                     "Healthy", "Healthy"), Average = c(108.915677, 103.148873, 40.3359607, 
                                                                        88.4329528, 87.7756577)), row.names = c("30566-001", "30566-002", 
                                                                                                                "30566-003", "30566-004", "30566-005"), class = "data.frame")

pheatmap(heat[,order(m[,"Average"], decreasing = TRUE)], 
         cluster_rows=TRUE, show_rownames=T,
         cluster_cols=FALSE, annotation_col=m)

Created on 2023-09-06 with reprex v2.0.2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.