{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"hidden": true
},
"outputs": [],
"source": [
"options(\n",
" repr.matrix.max.rows = 10, # smaller matrix output\n",
" repr.plot.res = 70, # smaller plots\n",
" repr.plot.height = 6, # leave room for the legend\n",
" jupyter.plot_mimetypes = # pretty plots in vignette\n",
" c('application/pdf', 'image/png'))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Interaction with the tidyverse and ggplot2\n",
"\n",
"The [tidyverse](https://www.tidyverse.org/), [ggplot2](http://ggplot2.tidyverse.org/), and destiny are a great fit!"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"suppressPackageStartupMessages({\n",
" library(destiny)\n",
" library(tidyverse)\n",
" library(forcats) # not in the default tidyverse loadout\n",
"})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"ggplot has a peculiar method to set default scales: You just have to define certain variables."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"scale_colour_continuous <- scale_color_viridis_c"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"When working mainly with dimension reductions, I suggest to hide the (useless) ticks:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"theme_set(theme_gray() + theme(\n",
" axis.ticks = element_blank(),\n",
" axis.text = element_blank()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let’s load our dataset"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"data(guo_norm)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Of course you could use [tidyr](http://tidyr.tidyverse.org/)::[gather()](https://rdrr.io/cran/tidyr/man/gather.html)
to tidy or transform the data now, but the data is already in the right form for destiny, and [R for Data Science](http://r4ds.had.co.nz/tidy-data.html) is a better resource for it than this vignette. The long form of a single cell `ExpressionSet` would look like:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
Cell | num_cells | Gene | Expression |
---|---|---|---|
2C 1.1 | 2 | Actb | -0.575 |
2C 1.2 | 2 | Actb | -0.435 |
2C 2.1 | 2 | Actb | 0.460 |
2C 2.2 | 2 | Actb | 0.610 |
2C 3.1 | 2 | Actb | 1.970 |
⋮ | ⋮ | ⋮ | ⋮ |
64C 7.10 | 64 | Tspan8 | 3.220 |
64C 7.11 | 64 | Tspan8 | 3.415 |
64C 7.12 | 64 | Tspan8 | 4.540 |
64C 7.13 | 64 | Tspan8 | 5.315 |
64C 7.14 | 64 | Tspan8 | 2.865 |