I made a heatmap with the following data (the actual table has 240 rows):
tf.log
0-dpi 1-dpi 7-dpi 14-dpi 22-dpi
TRINITY_DN0_c0_g1_i2 1.27584408 0.5872404 1.780178 1.414362 1.53341851
TRINITY_DN10214_c0_g1_i2 -2.34774378 -2.9194079 -3.211677 -2.885869 -2.04617227
TRINITY_DN10214_c0_g1_i6 -2.14867876 -1.5794957 -1.577811 -2.485095 -1.44172768
TRINITY_DN1038_c0_g1_i4 0.03163921 0.7375222 2.037936 2.462830 0.04559793
TRINITY_DN10462_c0_g1_i2 -2.63973533 -2.8039350 -2.481144 -2.698932 -1.76284020
TRINITY_DN1052_c0_g1_i3 -3.32767605 -2.2006082 -1.887869 -1.211592 -1.43292669
I then made the following heatmap:
heat.gen.k = Heatmap(tf.log, width = unit(10, "cm"),
km = 12,
cluster_columns = F,
show_row_names = F,
row_title_rot = 0,
row_gap = unit(3, "mm"),
name = "Log2FC",
column_title = "Resistant - Susceptible",
column_title_gp = gpar(fontfamily = "sans", fontsize = 28),
column_names_gp = gpar(fontfamily = "sans", fontsize = 20),
col = heat.col,
right_annotation = ha)
print(heat.gen.k)
I would like to pull the clusters out for downstream analysis but I cannot do so with the following code:
clusterlist = row_order(heat.gen.k)
clu_df <- lapply(names(clusterlist), function(i){
out <- data.frame(GeneID = rownames(tf.log[clusterlist[[i]],]),
Cluster = paste0("cluster", i),
stringsAsFactors = FALSE)
return(out)
}) %>%
do.call(rbind, .)
I keep getting the following error:
Error in data.frame(GeneID = rownames(tf.log[clusterlist[[i]], ]), Cluster = paste0("cluster", :
arguments imply differing number of rows: 0, 1
Not sure how to resolve this issue.
This worked. Thanks!
Hi! I have exactly the same problem but your solution did not solve it! So this is my original dataset (originally genes in rows and samples in column, total number of genes 516):
so I tidy up the dataset as follow:
and then make the heatmap (worked fine, divide cluster and so on ok):
the cluster are not made by one gene only so I should be able to retrieve the genes presents in the clusters:
but when I do the same code as reported :
I still get the same error:
What am I doing wrong??
Thank you!
Camilla
Isn't
clusterlist
just an ordinary list without names? I would probably do1:length(clusterlist)
rather thannames(clusterlist)
.thank for you reply! I did change it but same error:
Can you provide some reproducible data? (
dput
)what do you mean? I have a data frame with 7 samples in column and 516 genes in row. when I prepare the data for the heatmap, I remove the categorical variable, and convert into a matrix:
My dataset is like this:
And indeed the class of
mydata
andmat
is the same:[1] "matrix" "array"
and if I try to re-run the same code posted here issue with the same matrix (basically copu and paste) I got multiple errors which seems to be related to :