Compute a sample-by-sample distance matrix from a geneda
object and plot a ggplot2 heatmap. Optionally subset metadata columns and
reorder rows/columns by hierarchical clustering.
Usage
PlotDistances(
object,
method = "euclidean",
reorder = TRUE,
meta_cols = NULL,
palettes = NULL,
return = c("object", "plot")
)Arguments
- object
A
genedaobject- method
Distance method for stats::dist (default "euclidean")
- reorder
Logical; if TRUE, reorder rows/cols by hclust on the distance matrix. Default TRUE
- meta_cols
Optional character vector of metadata columns to display in the title/subtitle for quick reference (no annotation strips are drawn).
- palettes
Optional named list of color vectors that can be used downstream (returned) if the caller wants to annotate elsewhere.
- return
One of c("object", "plot"). If "plot", draws the heatmap immediately via grid and still returns the result list. Default "object".
Value
A list with elements: dist_matrix, order (character vector of sample names), heatmap (pheatmap object), palettes (as passed through)
Examples
data(Snail1KO)
counts <- as.matrix(Snail1KO$rawCounts)
counts <- counts[rowSums(counts >= 10) >= 3, ]
meta <- Snail1KO$metadata
rownames(meta) <- meta$Sample
norm <- log2(t(t(counts) / colSums(counts)) * 1e6 + 1)
obj <- GenEDA(normalized = norm, metadata = meta, counts = counts)
colorList <- list(Genotype = c(WT = "grey40", Snai1_KO = "firebrick3"))
dists <- PlotDistances(obj,
meta_cols = "Genotype", palettes = colorList,
return = "plot"
)
