Plots one similarity from smash_compare() (or smash_read_compare())
in one of four ways:
"matrix"a samples x samples tile plot of the similarity. With
subject, samples are grouped into blocks by subject (and ordered bytimewithin them), so pairs from the same subject sit on the diagonal blocks."distribution"histograms of the similarity over pairs of samples, split by whether the two samples are from the same subject (with
subject) and, withgroup, in one panel per group, using only pairs of samples from the same group (e.g. isolates of the same species, or metagenomes from the same source)."ordination"a principal coordinates analysis (PCoA,
stats::cmdscale()) of the distances 1 - similarity, with points coloured bycolor(by defaultsubject) and shaped byshape. Withgroup, a separate ordination for each group, in its own panel."network"samples as points (placed by the PCoA, or in a circle with
layout = "circle"), joined where the similarity is at leastthreshold: candidate shared strains or transmission events. For the directionalcontainmentandcontainment_ani, arrows point fromsample_1to the sample it is contained in,sample_2.
Arguments
- compare
A tibble from
smash_compare()orsmash_read_compare().- metric
The similarity to plot, a column of
compare: e.g."jaccard"(the default),"angular_similarity","containment","max_containment"or one of the ANI estimates such as"max_containment_ani". The ordination needs a symmetric similarity (not"containment"or"containment_ani").- type
"matrix","distribution","ordination"or"network".- subject
Optional sample column (as named in
smash_compare()'skeep, without the_1or_2) identifying the subject, e.g."host_subject_id".- group
Optional sample column to split the distribution and ordination into panels, e.g.
"species"(isolates) or"sample_source".- time
Optional sample column (a date or number) to order samples within subjects in the matrix.
- color, shape
Optional sample columns for point colour and shape in the ordination and network.
colordefaults tosubject, andshapeto"sample_type"when the samples include both isolates and metagenomes.- threshold
For the network, the similarity at or above which two samples are joined; also drawn as a dashed line on the distribution. Defaults to 0.995 for ANI estimates, and the 95th percentile of the similarity otherwise.
- sample_label
Optional sample column to label the samples with, in the matrix and network. Defaults to the sample IDs in the matrix, and no labels in the network.
- layout
For the network:
"pcoa"(the default) or"circle".- palette
A viridis palette option.
Details
Which similarity? For isolates, Jaccard similarity or its ANI
estimate compares whole genomes, while containment ANI (max_containment_ani
for a symmetric value) is robust to differences in genome size and
mobile elements; same-strain isolates typically have ANI of at least 0.995
(0.999 for recent transmission), best resolved at k = 51 and a small
scaled. For metagenomes, angular similarity (with abundances) or
Jaccard similarity compare whole communities, and the containment of an
isolate in a metagenome shows whether the metagenome holds its genome.
See also
smash_compare() for the similarities, and
smash_compare_matrix() for them as a matrix.
Examples
sketches <- smash_aggregate(smash_example("signatures"),
metadata = smash_example("runs"),
k = 31, min_abundance = 2)
cmp <- smash_compare(sketches)
smash_compare_plot(cmp, "jaccard", subject = "host_subject_id",
time = "collection_date")
smash_compare_plot(cmp, "angular_similarity", type = "distribution",
subject = "host_subject_id", group = "sample_source")
smash_compare_plot(cmp, "angular_similarity", type = "ordination",
subject = "host_subject_id", shape = "sample_source")
smash_compare_plot(cmp, "jaccard", type = "network",
subject = "host_subject_id", shape = "sample_source")
#> Joining samples with jaccard >= 0.236 (set `threshold` to change).