# NOT RUN {
data("Wood")
# regular heatmap from package stats
heatmap(Wood, main = "Wood (standard heatmap)")
# Default heatmap does Euclidean distance, hierarchical clustering with
# average-link and optimal leaf ordering
hmap(Wood, main = "Wood (opt. leaf ordering)")
# Heatmap shown without dendrograms (used pimage)
hmap(Wood, main = "Wood (opt. leaf ordering)", showDend = FALSE)
# Heatmap with correlation-based distance, green-red color (greenred is
# predefined) and optimal leaf ordering and no row label
dist_cor <- function(x) as.dist(1 - cor(t(x)))
hmap(Wood, distfun = dist_cor, col = greenred(100), row_labels = FALSE,
main = "Wood (reorded by corr. between obs.)")
# Heatmap with order based on the angle in two-dimensional MDS space.
hmap(Wood, method = "MDS_angle", col = greenred(100), row_labels = FALSE,
main = "Wood (reorderd using ange in MDS space)")
# Heatmap for distances
d <- dist(Wood)
hmap(d, method = "OLO", main = "Wood (Euclidean distances)")
# order-based with dissimilarity matrices
hmap(Wood, method = "MDS_angle", showdist = "both",
col = greenred(100), col_dist = greens(100),
keylab = "norm. Expression", main = "Wood (reporderd with distances)")
# Manually seriate and plot as pimage.
o <- seriate(Wood, method = "heatmap", control = list(dist_fun = dist, seriation_method = "OLO"))
o
pimage(Wood, o, prop = FALSE)
# Note: method heatmap calculates reorderd hclust objects which can be used for many heatmap
# implementations.
heatmap(Wood, Rowv = as.dendrogram(o[[1]]), Colv = as.dendrogram(o[[2]]))
# ggplot 2 version does not support dendrograms in the margin (for now)
if (require("ggplot2")) {
library("ggplot2")
gghmap(Wood) + labs(title = "Wood", subtitle = "Optimal leaf ordering")
# More parameters (see ? ggpimage): reverse column order and flip axes, make a proportional plot
gghmap(Wood, reverse_columns = TRUE) +
labs(title = "Wood", subtitle = "Optimal leaf ordering")
gghmap(Wood, flip_axes = TRUE) +
labs(title = "Wood", subtitle = "Optimal leaf ordering")
gghmap(Wood, flip_axes = TRUE, prop = TRUE) +
labs(title = "Wood", subtitle = "Optimal leaf ordering")
gghmap(Wood, distfun = dist_cor) +
labs(title = "Wood", subtitle = "Reorded by correlation between observations") +
scale_fill_gradient2(low = "darkgreen", high = "red")
gghmap(d, prop = TRUE) +
labs(title = "Wood", subtitle = "Euclidean distances, reordered)")
# Note: the ggplot2-based version cannot show distance matrices in the same plot.
# Manually seriate and plot as pimage.
o <- seriate(Wood, method = "heatmap", control = list(dist_fun = dist,
seriation_method = "OLO"))
o
ggpimage(Wood, o, prop = FALSE)
}
# }
Run the code above in your browser using DataLab