knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  out.width = "100%",
  fig.path = "man/figures/",
  message = FALSE,
  dpi = 300
)
set.seed(1)


ℹ️ Tutorials     ℹ️ Reference documentation

Visualise a single-cell trajectory as a graph or dendrogram, as a dimensionality reduction or heatmap of the expression data, or a comparison between two trajectories as a pairwise scatterplot or dimensionality reduction projection.

Here's a summary of the different plotting functions for visualising single-cell trajectories.

library(tidyverse)
library(dyno)

# get trajectory
data(example_bifurcating)

trajectory <- example_bifurcating %>% add_root()

# gather some prior information
grouping <- trajectory$prior_information$groups_id

groups <- tibble(
  group_id = trajectory$milestone_ids,
  color = dynplot:::milestone_palette_list$auto(length(group_id))
)
features_oi <- apply(as.matrix(trajectory$counts), 2, sd) %>% sort() %>% names() %>% tail(10)
feature_oi <- features_oi[[10]]

plot_dendro(): Plot a trajectory as a dendrogram

patchwork::wrap_plots(
  plot_dendro(trajectory) + labs(title = "Topology"),
  plot_dendro(trajectory, "milestone") + labs(title = "Ordering"),
  plot_dendro(trajectory, grouping=grouping, groups=groups) + labs(title = "Grouping/clustering"),
  plot_dendro(trajectory, feature_oi=feature_oi) + labs(title = "Expression of\na single gene"),
  plot_dendro(trajectory, "pseudotime") + labs(title = "Pseudotime"),
  byrow = TRUE,
  ncol = 3
) & theme(legend.position = "none")

plot_onedim(): Plot a trajectory as a one-dimensional set of connected segments

patchwork::wrap_plots(
  plot_onedim(trajectory) + labs(title = "Topology"),
  plot_onedim(trajectory, "milestone") + labs(title = "Ordering"),
  plot_onedim(trajectory, grouping=grouping, groups=groups) + labs(title = "Grouping/clustering"),
  plot_onedim(trajectory, feature_oi=feature_oi) + labs(title = "Expression of\na single gene"),
  plot_onedim(trajectory, "pseudotime") + labs(title = "Pseudotime"),
  byrow = TRUE,
  ncol = 2
) & theme(legend.position = "none")

plot_graph(): Plot a trajectory and cellular positions as a graph

patchwork::wrap_plots(
  plot_graph(trajectory) + labs(title = "Topology"),
  plot_graph(trajectory, "milestone") + labs(title = "Ordering"),
  plot_graph(trajectory, grouping=grouping, groups=groups) + labs(title = "Grouping/clustering"),
  plot_graph(trajectory, feature_oi=feature_oi) + labs(title = "Expression of\na single gene"),
  plot_graph(trajectory, "pseudotime") + labs(title = "Pseudotime"),
  byrow = TRUE,
  ncol = 3
) & theme(legend.position = "none")

plot_dimred(): Plot a trajectory in a (given) dimensionality reduction

patchwork::wrap_plots(
  plot_dimred(trajectory) + labs(title = "Topology"),
  plot_dimred(trajectory, "milestone") + labs(title = "Ordering"),
  plot_dimred(trajectory, grouping=grouping, groups=groups) + labs(title = "Grouping/clustering"),
  plot_dimred(trajectory, feature_oi=feature_oi) + labs(title = "Expression of\na single gene"),
  plot_dimred(trajectory, "pseudotime") + labs(title = "Pseudotime"),
  byrow = TRUE,
  ncol = 3
) & theme(legend.position = "none")

plot_heatmap(): Plot expression data along a trajectory

In addition, you can also plot the expression of genes along the trajectory as a heatmap.

plot_heatmap(trajectory, grouping = trajectory$prior_information$grouping_assignment)

plot_linearised_comparison(): Compare two trajectories as a pseudotime scatterplot

You can compare multiple trajectories (for the same cells) by creating a scatterplot between the two trajectories.

prediction <- infer_trajectory(trajectory, ti_comp1())

trajectory$id <- "Bifurcating"
prediction$id <- "Linear"
plot_linearised_comparison(trajectory, prediction)

Latest changes

Check out news(package = "dynwrap") or NEWS.md for a full list of changes.

cat(dynutils::recent_news())


dynverse/dynplot documentation built on Dec. 12, 2021, 9:39 p.m.