if (!("ggplot2" %in% installed.packages())) {
    install.packages('ggplot2')
}
library('ggplot2')
## Warning: package 'ggplot2' was built under R version 4.4.1
if (!("Seurat" %in% installed.packages())) {
    install.packages('Seurat')
}
library('Seurat')
## Loading required package: SeuratObject
## Loading required package: sp
## 
## Attaching package: 'SeuratObject'
## The following objects are masked from 'package:base':
## 
##     intersect, t
if (!("devtools" %in% installed.packages())) {
    install.packages('devtools')
}
if (!("canvasXpress" %in% installed.packages())) {
    devtools::install_github('neuhausi/canvasXpress')
}
#devtools::install_local("~/git/canvas/R/canvasXpress.tar.gz", build_manual = TRUE, upgrade = "always")
library('canvasXpress')

Load data and Libraries

https://satijalab.org/seurat/articles/visualization_vignette.html

SeuratData::InstallData("pbmc3k")
## Warning: The following packages are already installed and will not be
## reinstalled: pbmc3k
library(Seurat)
library(SeuratData)
## ── Installed datasets ──────────────────────────────── SeuratData v0.2.2.9001 ──
## ✔ cbmc   3.1.4                          ✔ pbmc3k 3.1.4
## ────────────────────────────────────── Key ─────────────────────────────────────
## ✔ Dataset loaded successfully
## ❯ Dataset built with a newer version of Seurat than installed
## ❓ Unknown version of Seurat installed
library(ggplot2)
library(ggridges)
library(patchwork)
pbmc3k.final <- LoadData("pbmc3k", type = "pbmc3k.final")
## Validating object structure
## Updating object slots
## Ensuring keys are in the proper structure
## Updating matrix keys for DimReduc 'pca'
## Updating matrix keys for DimReduc 'umap'
## Warning: Assay RNA changing from Assay to Assay
## Warning: Graph RNA_nn changing from Graph to Graph
## Warning: Graph RNA_snn changing from Graph to Graph
## Warning: DimReduc pca changing from DimReduc to DimReduc
## Warning: DimReduc umap changing from DimReduc to DimReduc
## Ensuring keys are in the proper structure
## Ensuring feature names don't have underscores or pipes
## Updating slots in RNA
## Updating slots in RNA_nn
## Setting default assay of RNA_nn to RNA
## Updating slots in RNA_snn
## Setting default assay of RNA_snn to RNA
## Updating slots in pca
## Updating slots in umap
## Setting umap DimReduc to global
## Setting assay used for NormalizeData.RNA to RNA
## Setting assay used for FindVariableFeatures.RNA to RNA
## Setting assay used for ScaleData.RNA to RNA
## Setting assay used for RunPCA.RNA to RNA
## Setting assay used for JackStraw.RNA.pca to RNA
## No assay information could be found for ScoreJackStraw
## Warning: Adding a command log without an assay associated with it
## Setting assay used for FindNeighbors.RNA.pca to RNA
## No assay information could be found for FindClusters
## Warning: Adding a command log without an assay associated with it
## Setting assay used for RunUMAP.RNA.pca to RNA
## Validating object structure for Assay 'RNA'
## Validating object structure for Graph 'RNA_nn'
## Validating object structure for Graph 'RNA_snn'
## Validating object structure for DimReduc 'pca'
## Validating object structure for DimReduc 'umap'
## Object representation is consistent with the most current Seurat version
## Warning: Assay RNA changing from Assay to Assay5
pbmc3k.final$groups <- sample(c("group1", "group2"), size = ncol(pbmc3k.final), replace = TRUE)
features <- c("LYZ", "CCL5", "IL32", "PTPRCAP", "FCGR3A", "PF4")
pbmc3k.final
## An object of class Seurat 
## 13714 features across 2638 samples within 1 assay 
## Active assay: RNA (13714 features, 2000 variable features)
##  3 layers present: data, counts, scale.data
##  2 dimensional reductions calculated: pca, umap

Five visualizations of marker feature expression

Ridge plots - from ggridges. Visualize single cell expression distributions in each cluster

r = RidgePlot(pbmc3k.final, features = features, ncol = 2)
r
## Picking joint bandwidth of 0.318
## Picking joint bandwidth of 0.177
## Picking joint bandwidth of 0.161
## Picking joint bandwidth of 0.15
## Picking joint bandwidth of 0.0894
## Picking joint bandwidth of 0.0298

canvasXpress(r)
## Picking joint bandwidth of 0.318
## Picking joint bandwidth of 0.177
## Picking joint bandwidth of 0.161
## Picking joint bandwidth of 0.15
## Picking joint bandwidth of 0.0894
## Picking joint bandwidth of 0.0298

Dot plots - SplitDotPlotGG has been replaced with the split.by parameter for DotPlot

d = DotPlot(pbmc3k.final, features = features, split.by = "groups") + RotatedAxis()
d

canvasXpress(d)

Violin plot - Visualize single cell expression distributions in each cluster

v = VlnPlot(pbmc3k.final, features = features)
v

canvasXpress(v)

Violin plots can also be split on some variable. Simply add the splitting variable to object metadata and pass it to the split.by argument

v2 = VlnPlot(pbmc3k.final, features = "percent.mt", split.by = "groups")
## The default behaviour of split.by has changed.
## Separate violin plots are now plotted side-by-side.
## To restore the old behaviour of a single split violin,
## set split.plot = TRUE.
##       
## This message will be shown once per session.
v2

canvasXpress(v2)

Feature plot - visualize feature expression in low-dimensional space

f = FeaturePlot(pbmc3k.final, features = features)
f

canvasXpress(f)

DimPlot replaces TSNEPlot, PCAPlot, etc. In addition, it will plot either ‘umap’, ‘tsne’, or ‘pca’ by default, in that order

s = DimPlot(pbmc3k.final)
s

canvasXpress(s)

Dot plots - SplitDotPlotGG has been replaced with the split.by parameter for DotPlot

d = DotPlot(pbmc3k.final, features = features, split.by = "groups") + RotatedAxis()
d

canvasXpress(d)

Single cell heatmap of feature expression

h = DoHeatmap(subset(pbmc3k.final, downsample = 100), features = features, size = 3)
h

canvasXpress(h)

Senssion Info

sessionInfo()
## R version 4.4.0 (2024-04-24)
## Platform: aarch64-apple-darwin20
## Running under: macOS 15.5
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib 
## LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## time zone: America/New_York
## tzcode source: internal
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] patchwork_1.2.0         ggridges_0.5.6          pbmc3k.SeuratData_3.1.4
##  [4] cbmc.SeuratData_3.1.4   SeuratData_0.2.2.9001   canvasXpress_1.50.5    
##  [7] Seurat_5.1.0            SeuratObject_5.0.2      sp_2.1-4               
## [10] ggplot2_3.5.2          
## 
## loaded via a namespace (and not attached):
##   [1] deldir_2.0-4           pbapply_1.7-2          gridExtra_2.3         
##   [4] rlang_1.1.6            magrittr_2.0.3         RcppAnnoy_0.0.22      
##   [7] spatstat.geom_3.2-9    matrixStats_1.3.0      compiler_4.4.0        
##  [10] png_0.1-8              vctrs_0.6.5            reshape2_1.4.4        
##  [13] stringr_1.5.1          crayon_1.5.3           pkgconfig_2.0.3       
##  [16] fastmap_1.2.0          labeling_0.4.3         promises_1.3.3        
##  [19] rmarkdown_2.29         purrr_1.0.4            xfun_0.52             
##  [22] cachem_1.1.0           jsonlite_2.0.0         goftest_1.2-3         
##  [25] later_1.4.2            spatstat.utils_3.0-4   irlba_2.3.5.1         
##  [28] parallel_4.4.0         cluster_2.1.6          R6_2.6.1              
##  [31] ica_1.0-3              bslib_0.9.0            stringi_1.8.7         
##  [34] RColorBrewer_1.1-3     spatstat.data_3.0-4    reticulate_1.36.1     
##  [37] parallelly_1.37.1      lmtest_0.9-40          jquerylib_0.1.4       
##  [40] scattermore_1.2        Rcpp_1.0.14            knitr_1.50            
##  [43] tensor_1.5             future.apply_1.11.2    zoo_1.8-12            
##  [46] sctransform_0.4.1      httpuv_1.6.15          Matrix_1.7-0          
##  [49] splines_4.4.0          igraph_2.0.3           tidyselect_1.2.1      
##  [52] abind_1.4-5            rstudioapi_0.16.0      yaml_2.3.10           
##  [55] spatstat.random_3.2-3  codetools_0.2-20       miniUI_0.1.1.1        
##  [58] spatstat.explore_3.2-7 listenv_0.9.1          lattice_0.22-6        
##  [61] tibble_3.3.0           plyr_1.8.9             shiny_1.8.1.1         
##  [64] withr_3.0.2            ROCR_1.0-11            evaluate_1.0.4        
##  [67] Rtsne_0.17             future_1.33.2          fastDummies_1.7.3     
##  [70] survival_3.6-4         polyclip_1.10-6        fitdistrplus_1.1-11   
##  [73] pillar_1.10.2          KernSmooth_2.23-24     plotly_4.10.4         
##  [76] generics_0.1.4         RcppHNSW_0.6.0         scales_1.4.0          
##  [79] globals_0.16.3         xtable_1.8-4           glue_1.8.0            
##  [82] lazyeval_0.2.2         tools_4.4.0            data.table_1.17.4     
##  [85] RSpectra_0.16-1        RANN_2.6.1             leiden_0.4.3.1        
##  [88] dotCall64_1.1-1        cowplot_1.1.3          grid_4.4.0            
##  [91] tidyr_1.3.1            colorspace_2.1-1       nlme_3.1-164          
##  [94] cli_3.6.5              rappdirs_0.3.3         spatstat.sparse_3.0-3 
##  [97] spam_2.10-0            viridisLite_0.4.2      dplyr_1.1.4           
## [100] uwot_0.2.2             gtable_0.3.6           sass_0.4.10           
## [103] digest_0.6.37          progressr_0.14.0       ggrepel_0.9.5         
## [106] htmlwidgets_1.6.4      farver_2.1.2           htmltools_0.5.8.1     
## [109] lifecycle_1.0.4        httr_1.4.7             mime_0.13             
## [112] MASS_7.3-60.2