Reorder rows of pheatmap using listed order

  Kiến thức lập trình

I’m making individual heatmaps for lists of genes in some transcriptomics works, but pheatmap() keeps scrambling my desired order.

Filtering data frame to include interesting genes from given list:

hit.ecm <- c("LAMA1", "LAMB1", "LAMC1", "LAMA3", "LAMB3", "LAMC2", "COL4A1", "COL4A2", "COL7A1", "NID1", "DAG1", "HSPG2" ) <- dplyr::filter(ordered.logcpm.x.df, row.names(ordered.logcpm.x.df) %in% hit.ecm)
    Sample1         Sample4      ...
HSPG2   5.946018753 8.207376914
LAMC1   8.922318668 10.12384927
LAMC2   10.61406736 10.39705838
LAMB3   8.256238567 9.509676595
NID1    0.290159073 0.643989673
COL7A1  7.245084372 8.249219026
DAG1    8.129360081 8.395974748
LAMB1   8.874840072 9.046171411
COL4A1  7.753791954 6.175460555
COL4A2  8.398450047 8.007270104
LAMA1   2.276204643 0.50102742
LAMA3   10.40472836 10.59736716

Heatmap generation:

hm_hitecmdata <- pheatmap(,
         main="ECM Markers",
         cluster_rows = F,
         cluster_cols = F,
         show_rownames = T,
         show_colnames = F,
         border_color = F)

Resulting heatmap

I can manually order the rows of the data frame, but this method is very inefficient given the dozens of lists I’m working with.

ordered.ecm <-[c(11,8,2,12,4,3,9,10,6,5,7,1),]

How can I keep the same order as the lists that I input?

New contributor

mellifluous is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.