Useful for tracing a few select individuals over time on an ordination plot. Samples in phyloseq must be arranged in order of timepoint for the path connections to be drawn in the correct order! You can arrange the samples in timepoint order with ps_arrange.
ggplot scatterplot such as the output of ord_plot
name of variable used to identify grouping of points
values of id_var variable used to identify groups of points to draw
ggplot aesthetics created by aes(), e.g. aes(colour = ?) - group is already set to id_var internally!
arrowhead to add to path, NULL for none
additional arguments passed to geom_path
ggplot with added layer with geom_path
library(ggplot2)
data("dietswap", package = "microbiome")
# arrange by timepoint first (or whatever your own time variable is)
dietswap %>%
ps_arrange(timepoint) %>%
tax_fix() %>%
tax_transform("clr", rank = "Genus") %>%
ord_calc(method = "PCA") %>%
ord_plot(colour = "timepoint", alpha = 0.5, size = 2) %>%
add_paths(
id_var = "subject", id_values = c("azl", "byn"),
mapping = aes(colour = timepoint), linewidth = 1.5
# size = 1.5 # size instead of linewidth in older ggplot2 versions
)
# paths do NOT connect points in the correct order without arranging first
dietswap %>%
tax_fix() %>%
tax_transform("clr", rank = "Genus") %>%
ord_calc(method = "PCA") %>%
ord_plot(colour = "timepoint", alpha = 0.5) %>%
add_paths(
id_var = "subject", id_values = c("azl", "byn"),
mapping = aes(colour = timepoint), linewidth = 1.5
# size = 1.5 # size instead of linewidth in older ggplot2 versions
) +
ggtitle("WRONG PATH ORDER", "use ps_arrange first!")