Gplots Heatmap
- I'm visualizing a data set with the heatmap.2 function from the gplots package in R. Basically I'm performing a hierarchical clustering analysis on the original data, while forcing the heatmap to display a limited version of the data (between -3 and +3) to limit the effect of outliers on the appearance of the heatmap, while still retaining the.
- Hi, I have analyzed my deep sequencing data with DESeq and successfully generated a heatmap showing differentially expressed miRNAs by using gplots heatmap.2. However, I want to put different colors to.
Enhanced heatmap representation with partition and summary statistics (optional). This is an enhanced version of `heatmap.2' function in the Package gplots. The enhancement includes: 1) Improved. Most basic heatmap with ggplot2 This is the most basic heatmap you can build with R and ggplot2, using the geomtile function. Input data must be a long format where each row provides an observation. Figure 3: Heatmap with Manual Color Range in Base R. Example 2: Create Heatmap with geomtile Function ggplot2 Package As already mentioned in the beginning of this page, many R packages are providing functions for the creation of heatmaps in R.
I hope the code here is fairly self-explanatory with the inset annotations. I feel this is just a bit ‘prettier’ than heatmap.2 and has for me the right balance of options and extensibility. I have also found it difficult to produce high quality plots with heatmap.2- whereas ggplots especially with RStudio assistance in resizing PNG turn out better IMHO.
Here is quick example with the same colourscheme as gplots::heatmap.2
Related
With InteractiveComplexHeatmap, the following heatmaps can be exported as an interactive Shiny app:
- heatmaps directly produced from ComplexHeatmap,
- heatmaps from other functions or packages which are implement with ComplexHeatmap,
- heatmaps originally produced by
stats::heatmap()
,gplots::heatmap.2()
andpheatmap::pheatmap()
, but can be reproduced by the “translationfunctions”:ComplexHeatmap:::heatmap()
,ComplexHeatmap:::heatmap.2()
andComplexHeatmap::pheatmap()
.
All these types of heatmaps can be turned into interactive just by callinghtShiny()
after the heatmaps are drawn. E.g.:
which means you don’t need to touch your heatmap code. After you see the heatmap in your R terminal,directly calling htShiny()
with no argument will produce an interactive heatmap, like magic. :P
Plots Heatmap
Now there is a fourth scenario where the heatmap is produced by third-partyfunctions which uses stats::heatmap()
, gplots::heatmap.2()
orpheatmap::pheatmap()
. Since now we cannot directly interact withheatmap()
, heatmap.2()
or pheatmap()
, how can we turn these heatmaps intointeractive? The solution is fairly simple. We just need to go to e.g.pheatmapnamespace and replace pheatmap
with ComplexHeatmap::pheatmap
.
The following example is from the SC3 package wherefunction sc3_plot_expression()
internally uses pheatmap()
.
To replace the internally use of pheatmap::pheatmap
withComplexHeatmap::pheatmap
, we can use assignInNamespace()
to directlychange the value of pheatmap
in pheatmap namespace. After that,recalling sc3_plot_expression()
will directly useComplexHeatmap::pheatmap()
and now you can use htShiny()
to export it asan interactive app. Of course, you need to regenerate the heatmap with thesame code.
If you check the source code of sc3_plot_expression()
, pheatmap()
is usedby explicitely adding its namespace (check the last few lines of the function definition):
In this case, changing pheatmap
in pheatmap namespace directly affects sc3_plot_expression()
.
However, if the heatmap function is called without adding the namespace, youneed to first unload the package, modify the heatmap function in the heatmapnamespace and later load the package back.
Gplots Heatmap Example
Let’s look at the next example from GOexpress package where the function heatmap_GO()
internally use heatmap.2()
.
Now note in heatmap_GO()
function, heatmap.2()
is used without gplots namespace (go tothe end of the function definition listed below).
Gplots Heatmap.2 Function
In this case, the GOexpression namespace should firstly be removed bydetach()
, or else heatmap_GO()
will still use gplots::heatmap.2()
.
In the end, to safely change all stats::heatmap()
, gplots::heatmap.2()
andpheatmap::pheatmap()
to ComplexHeatmap:::heatmap()
,ComplexHeatmap:::heatmap.2()
and ComplexHeatmap::pheatmap()
, you can add following linesat the start of your R script: