annotated_dendrogram: annotated_dendrogram

View source: R/annotated_dendrogram.R

annotated_dendrogramR Documentation

annotated_dendrogram

Description

Creates an annotated dendrogram from a distance matrix. Dendrogram annotations are based on metadata supplied

Usage

annotated_dendrogram(
  dist,
  met,
  id,
  method = "complete",
  coord = NULL,
  pal = NULL
)

Arguments

dist

class dist. distance matrix

met

dataframe. samples in rows, metadata variables in columns.

id

string. sample identifier. must be a column in met

method

string. agglomeration method used by hclust.

coord

numeric vector. optional. allows you to specify coordinates of annotations. Vector must be same length as number of variables supplied. Leave as NULL for default coordinates.

pal

named vector. Colours to be used for each variable. see details section. Set to NULL to use default (RColorBrewer) colours.

Details

pal should be named vector of colours, where number of colour values needs to match the number variable values pal names should be variable, value, separated by :

Value

ggplot

Examples

set.seed(1)
# get relative abundance data
data(dss_example)
ddata <- dss_example$merged_abundance_id[,2:26]
rownames(ddata) <- dss_example$merged_abundance_id[,1]
ddata <- t(OCMSutility::relab(ddata))
# distance matrix
mydist <- vegan::vegdist(ddata, method='bray')

# metdata variable
mdata <- dss_example$metadata
mdata <- mdata[,c('sampleID','Genotype','Phenotype')]
annotated_dendrogram(mydist, mdata, 'sampleID')
# custom colours
col_geno <- RColorBrewer::brewer.pal(9, "Paired")[1:2]
names(col_geno) <- c('Genotype:WT','Genotype:KO')
col_phen <- RColorBrewer::brewer.pal(9, "Paired")[3:4]
names(col_phen) <- c('Phenotype:water','Phenotype:DSS')
annotated_dendrogram(mydist, mdata, 'sampleID', pal=c(col_geno, col_phen))

OxfordCMS/OCMSutility documentation built on Feb. 27, 2025, 8:19 p.m.