---
title: "Plotting a toy datasets using dynplot"
date: "`r Sys.Date()`"
output: 
  rmarkdown::html_vignette:
    fig_width: 5
    fig_height: 4 
vignette: >
  %\VignetteIndexEntry{generate_file_from_container(x)}
  %\VignetteEncoding{UTF-8}
  %\VignetteEngine{knitr::rmarkdown}
editor_options: 
  chunk_output_type: console
---

```{r setup, include = FALSE}
library(dplyr)
library(dynplot)
library(dynutils)
library(dynwrap)

set.seed(3)
```

Load in a toy dataset
```{r}
data(example_bifurcating)
trajectory <- example_bifurcating
```

## Plotting the topology and cellular positions

If the topology is very simple (or should be represented in one dimension)
```{r onedim}
plot_onedim(trajectory)
```

If the topology is a tree
```{r dendro}
plot_dendro(trajectory)
```

If the topology is more complex
```{r graph}
plot_graph(trajectory)
```

```{r}
plot_topology(trajectory, layout = "circle")
```

```{r}
plot_dimred(trajectory)
plot_dimred(trajectory, color_trajectory = "nearest")
```

## Plotting a grouping or clustering
```{r}
grouping <- trajectory$prior_information$groups_id
```

```{r grouping}
plot_onedim(trajectory, grouping = grouping)
plot_dendro(trajectory, grouping = grouping)
plot_graph(trajectory, grouping = grouping)
plot_dimred(trajectory, grouping = grouping)
```

## Plotting expression of one feature
```{r}
feature_oi <- first(colnames(trajectory$counts))
```

```{r expression}
plot_onedim(trajectory, feature_oi = feature_oi)
plot_dendro(trajectory, feature_oi = feature_oi)
plot_graph(trajectory, feature_oi = feature_oi)
plot_dimred(trajectory, feature_oi = feature_oi)
```

## Plotting expression of a lot of features

```{r heatmap}
plot_heatmap(trajectory)
```

## Comparing trajectories
```{r}
pseudotime <- trajectory$counts %>% prcomp() %>% {.$x[, 1]}
prediction <- 
  dynwrap::wrap_data(id = "dummy_prediction", cell_ids = trajectory$cell_ids) %>%
  dynwrap::add_linear_trajectory(pseudotime)

plot_linearised_comparison(trajectory, prediction)
```

