Skip to content

Commit

Permalink
Update statistics vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel-marsh committed Nov 13, 2024
1 parent c136659 commit baa6f49
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions vignettes/articles/Statistics.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ For this vignette I will be utilizing pbmc3k dataset from the SeuratData package
```{r init}
# Load Packages
library(ggplot2)
library(patchwork)
library(dplyr)
library(magrittr)
library(Seurat)
Expand All @@ -72,6 +73,10 @@ pbmc$orig.ident <- sample(c("sample1", "sample2", "sample3", "sample4"), size =
[email protected]$group[[email protected]$orig.ident == "sample1" | [email protected]$orig.ident == "sample3"] <- "Group 1"
[email protected]$group[[email protected]$orig.ident == "sample2" | [email protected]$orig.ident == "sample4"] <- "Group 2"
[email protected]$treatment[[email protected]$orig.ident == "sample1"] <- "Control"
[email protected]$treatment[[email protected]$orig.ident == "sample2" | [email protected]$orig.ident == "sample4" | [email protected]$orig.ident == "sample3"] <- "Treated"
# Add dummy module score
pbmc <- AddModuleScore(object = pbmc, features = list(c("CD3E", "CD4", "THY1", "TCRA")), name = "module_score")
```
Expand Down Expand Up @@ -111,6 +116,45 @@ cluster_stats %>%
```


## Plotting Cluster/Identity Proportions
Understanding the proportion of cells per cluster and how that may change across a group can be important aspect of single cell analysis. scCustomize contains function `Proportion_Plot` to provide some visualization of cell proportions.

Plotting proportionality can be tricky especially when dealing with clusters of very disparate sizes (especially small clusters) so plese be aware to examine raw data as well (see `Cluster_Stats_All_Samples()`).

Also note that when splitting plot by group there are now error bars on these plots for interpretation of variance and other plotting methods should be used to convery such information.

### Basic Proportion Plots
`Proportion_Plot` can either return a bar graph or pie graph depending on parameter value for
```{r eval=FALSE}
Proportion_Plot(seurat_object = pbmc, plot_type = "bar")
Proportion_Plot(seurat_object = pbmc, plot_type = "pie")
```

```{r echo=FALSE, fig.height=7, fig.width=13, fig.align='center'}
p1 <- Proportion_Plot(seurat_object = pbmc, plot_type = "bar")
p2 <- Proportion_Plot(seurat_object = pbmc, plot_type = "pie")
wrap_plots(p1, p2)
```

### Plot across groups
Like other plots you can also use `Proportion_Plot` to split plot across any categorical meta.data variable.
```{r fig.height=7, fig.width=13, fig.align='center'}
Proportion_Plot(seurat_object = pbmc, plot_type = "bar", split.by = "treatment")
```
```{r fig.height=7, fig.width=13, fig.align='center'}
Proportion_Plot(seurat_object = pbmc, plot_type = "pie", split.by = "treatment")
```

### Plot raw cell numbers
The default for `Proportion_Plot` is to plot the proportion of cells and not the raw number of cells per identity because that can be deceptive. However, in some cases it can be useful and so users can change the `plot_scale` parameter to plot raw numbers of cells instead of proportions.
```{r fig.height=7, fig.width=13, fig.align='center'}
Proportion_Plot(seurat_object = pbmc, plot_type = "bar", split.by = "treatment", plot_scale = "count")
```


## Percent of Cells Expressing Feature(s)
It can also be informative to understand the percent of cells/nuclei that express a given feature or set of features.
scCustomize provides the `Percent_Expressing` function to return these results.
Expand Down Expand Up @@ -248,3 +292,4 @@ p3 <- Plot_Median_Other(seurat_object = pbmc, median_var = "module_score1", grou
patchwork::wrap_plots(p1, p2, p3, ncol = 3)
```


0 comments on commit baa6f49

Please sign in to comment.