View source: R/annotated_dendrogram.R
annotated_dendrogram | R Documentation |
Creates an annotated dendrogram from a distance matrix. Dendrogram annotations are based on metadata supplied
annotated_dendrogram(
dist,
met,
id,
method = "complete",
coord = NULL,
pal = NULL
)
dist |
class |
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 |
coord |
numeric vector. optional. allows you to specify coordinates
of annotations. Vector must be same length as number of variables supplied.
Leave as |
pal |
named vector. Colours to be used for each variable. see details section.
Set to |
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 :
ggplot
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.