I have a matrix "data" like this
Sample1 Sample2 Sample3 Sample4 Sample5 Sample6 Sample7
AC008870.3 1.0502 1.5076 1.3916 0.3655 1.1028 0.6700 1.6719
TLX1NB 2.0357 1.6799 -0.5898 -0.2286 1.8068 2.0801 2.1399
LINC00511 1.6435 1.3586 1.5394 1.0144 0.6329 1.6717 0.9201
PRC1-AS1 1.3657 1.5695 0.7393 0.8945 1.6971 0.7516 1.8048
AL161431.1 -0.6128 -0.6128 2.5562 -0.2102 -0.1496 -0.3387 -0.2035
AC022784.1 -1.0502 -0.1724 0.4127 2.3219 -0.6579 1.4954 -0.5929
LINC00518 -0.6053 -0.4479 -0.3621 0.0543 0.9048 0.1343 0.0658
C5orf66-AS1 0.2909 0.0603 0.3172 -0.3273 0.3660 -0.0113 -0.0723
AL589182.1 0.4675 1.9790 -0.6627 1.4468 0.4681 -0.6627 1.4636
LINC01705 1.8079 -0.1598 1.0448 0.0201 -0.0780 1.8574 1.0598
AC007639.1 1.8472 1.5940 1.6298 0.7072 0.8901 1.4685 0.8939
AL139099.5 0.4277 0.2271 0.5286 1.4965 1.2302 0.9821 1.1370
And the column data is in a dataframe "df"
Samples Type Type2
Sample1 M AT
Sample2 M AT
Sample3 M AT
Sample4 N PT
Sample5 N PT
Sample6 N PT
Sample7 M AT
I'm able to make a heatmap using complex heatmap
package, but a bit confused in adding column annotation to the heatmap.
pdf("heatmap.pdf", width=7, height=6.5)
Heatmap(data, name = "expression", col = greenred(75),
show_row_names = FALSE, show_column_names = FALSE,cluster_rows = TRUE,
cluster_columns = TRUE,show_column_dend = TRUE,show_row_dend = TRUE,
row_dend_reorder = TRUE,column_dend_reorder = TRUE,clustering_method_rows = "ward.D2",
clustering_method_columns = "ward.D2",width = unit(100, "mm"))
dev.off()
How to add column annotation to the heatmap? Any help is appreciated.
Thank you very much Kevin.
You are very welcome.
One question. How to adjust the expression color? On my plot 15,10 (red), 5 (black), 0,-5 (green) was displayed and the whole plot was in green color. May I know how to adjust that? Check this plot
matrix with values is logCPM. When I used heatmap.2 function it looks fine. But when I'm using complexheatmap the whole plot was in green color
Yes, your heatmap just looks a bit 'flat', which can frequently happen but which does not necessarily mean that your data is incorrect. In such situations, it can be a good idea to plot Z-scaled data, which means, for example, that a value of +2 represents 2 standard deviations (sdevs) above the mean, whereas, -2 represents 2 sdevs below the mean, et cetera.
You can also quite easily specify your own colour scheme via the
colorRampPalette()
andcolorRamp2()
functions (from circlize package). If you scale your own data, it's also a good idea to specify your own 'breaks', i.e., thresholds in your data that indicate where colour should change. Doing this can help to exaggerate, for example, lower values. One then supplies the colour scheme and the breaks to the col parameter of theHeatmap()
function, like this:col=colorRamp2(myBreaks, myCol)
Here, I generate your same heatmap twice with a different colour scheme and breaks.
Actually the matrix which I posted in my question was Z-scaled data only. From the logCPM mentioned in edgeR tutorial I used
logCPM <- t(scale(t(logCPM)))
and then used it for heatmap. I adjusted the expression withbreaks
and it looks fine. Thanks a lot again.Sorry Kevin, if I have two time points of single cell RNA-seq data, in time point 1 cells can be clustered to 2 clusters, Lets say for example in time point 1, cell1, cell9, .. (99 cells) placed in sub cluster 1, cell4, cell12,,, (34 cells) in sub cluster 2. I have also 2 sub-clusters for time point 2. I have 200 genes. I want to heat map these 200 genes so columns have annotation for example time point 1-sub-cluster1, time point1-sub-cluster2, time point2-subcluster 1 and time point2-subcluster2 something like this picture
That each day has sub clusters a, b, c, ..
May you please help me
Hello, I would post this as a new Question. I am unavailable for a number of days.