Generates a plot of the location of spots/cells within an spatial sample, and colors them according to gene expression levels or spot/cell-level metadata

STplot(
  x,
  samples = NULL,
  genes = NULL,
  plot_meta = NULL,
  ks = "dtc",
  ws = NULL,
  deepSplit = NULL,
  color_pal = NULL,
  data_type = "tr",
  ptsize = NULL
)

Arguments

x

an STlist

samples

a vector of numbers indicating the ST samples to plot, or their sample names. If vector of numbers, it follow the order of samples in names(x@counts). If NULL, the function plots all samples

genes

a vector of gene names or a named list of gene sets. In the latter case, the averaged expression of genes within the sets is plotted

plot_meta

a column name in x@spatial_meta to plot

ks

the k values to plot or 'dtc' to plot results from dynamicTreeCut clustering solutions. Requires previous analysis with STclust

ws

the spatial weights to plot samples if STclust was used

deepSplit

a logical or positive number indicating the deepSplit, if samples were analyzed with STclust

color_pal

a string of a color palette from khroma or RColorBrewer, or a vector with enough color names or HEX values

data_type

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

ptsize

a number specifying the size of the points. Passed to the size aesthetic.

Value

a list of plots

Details

The function takes an STlist and plots the cells or spots in their spatial context. The users can color the spots/cells according to the expression of selected genes, cluster memberships, or any spot/cell level metadata included in x@spatial_meta. The function also can average expression of gene sets.

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!
#> 
melanoma <- transform_data(melanoma)
STplot(melanoma, gene='MLANA', samples='ST_mel1_rep2', ptsize=1)
#> $MLANA_ST_mel1_rep2

#>