Generates density plots, violin plots, and/or boxplots for the distribution of count values

plot_counts(
  x = NULL,
  samples = NULL,
  data_type = "tr",
  plot_type = "density",
  color_pal = "okabeito",
  cvalpha = 0.5,
  distrib_subset = 0.5,
  subset_seed = 12345
)

Arguments

x

an STlist

samples

samples to include in the plot. Default (NULL) includes all samples

data_type

one of tr or raw, to plot transformed or raw counts

plot_type

one or several of density, violin, and box, to generate density plots, violin plots, and/or boxplots

color_pal

a string of a color palette from khroma or RColorBrewer, or a vector with colors

cvalpha

the transparency of the density plots

distrib_subset

the proportion of spots/cells to plot. Generating these plots can be time consuming due to the large amount of elements to plot. This argument provides control on how many randomly values to show to speed plotting

subset_seed

related to distrib_subset. Sets the seed number to ensure the same subset of values is selected for plotting

Value

a list of ggplot objects

Details

The function allows to visualize the distribution counts across all genes and spots in the STlist. The user can select between density plots, violin plots, or box plots as visualization options. Useful for assessment of the effect of filtering and data transformations and to assess zero-inflation. To plot counts or genes per spot/cell, the function distribution_plots should be used instead.

Examples

# Using included melanoma example (Thrane et al.)
library('spatialGE')
data_files <- list.files(system.file("extdata", package="spatialGE"), recursive=T, full.names=T)
count_files <- grep("counts", data_files, value=T)
coord_files <- grep("mapping", data_files, value=T)
clin_file <- grep("thrane_clinical", data_files, value=T)
melanoma <- STlist(rnacounts=count_files[c(1,2)], spotcoords=coord_files[c(1,2)], samples=clin_file) # Only first two samples
#> Warning: Sample ST_mel2_rep1 was not found among the count/coordinate files.
#> Warning: Sample ST_mel2_rep2 was not found among the count/coordinate files.
#> Warning: Sample ST_mel3_rep1 was not found among the count/coordinate files.
#> Warning: Sample ST_mel3_rep2 was not found among the count/coordinate files.
#> Warning: Sample ST_mel4_rep1 was not found among the count/coordinate files.
#> Warning: Sample ST_mel4_rep2 was not found among the count/coordinate files.
#> Found matrix data
#> Matching gene expression and coordinate data...
#> Converting counts to sparse matrices
#> Completed STlist!
#> 
cp <- plot_counts(melanoma, data_type='raw', plot_type=c('violin', 'box'))
ggpubr::ggarrange(plotlist=cp)