vis_gene | R Documentation |
This function visualizes the gene expression stored in assays(spe)
or any
continuous variable stored in colData(spe)
for one given sample at the
spot-level using (by default) the histology information on the background.
To visualize clusters (or any discrete variable) use vis_clus()
.
vis_gene(
spe,
sampleid = unique(spe$sample_id)[1],
geneid = rowData(spe)$gene_search[1],
spatial = TRUE,
assayname = "logcounts",
minCount = 0,
viridis = TRUE,
image_id = "lowres",
alpha = NA,
cont_colors = if (viridis) viridisLite::viridis(21) else c("aquamarine4",
"springgreen", "goldenrod", "red"),
point_size = 2,
auto_crop = TRUE,
na_color = "#CCCCCC40",
multi_gene_method = c("z_score", "pca", "sparsity"),
is_stitched = FALSE,
...
)
spe |
A
SpatialExperiment-class
object. See |
sampleid |
A |
geneid |
A |
spatial |
A |
assayname |
The name of the |
minCount |
A |
viridis |
A |
image_id |
A |
alpha |
A |
cont_colors |
A |
point_size |
A |
auto_crop |
A |
na_color |
A |
multi_gene_method |
A |
is_stitched |
A |
... |
Passed to paste0() for making the title of the
plot following the |
This function subsets spe
to the given sample and prepares the
data and title for vis_gene_p()
. It also adds a caption to the plot.
A ggplot2 object.
Other Spatial gene visualization functions:
vis_gene_p()
,
vis_grid_gene()
if (enough_ram()) {
## Obtain the necessary data
if (!exists("spe")) spe <- fetch_data("spe")
## Valid `geneid` values are those in
head(rowData(spe)$gene_search)
## or continuous variables stored in colData(spe)
## or rownames(spe)
## Visualize a default gene on the non-viridis scale
p1 <- vis_gene(
spe = spe,
sampleid = "151507",
viridis = FALSE
)
print(p1)
## Use a custom set of colors in the reverse order than usual
p2 <- vis_gene(
spe = spe,
sampleid = "151507",
cont_colors = rev(viridisLite::viridis(21, option = "magma"))
)
print(p2)
## Turn the alpha to 1, which makes the NA values have a full alpha
p2b <- vis_gene(
spe = spe,
sampleid = "151507",
cont_colors = rev(viridisLite::viridis(21, option = "magma")),
alpha = 1
)
print(p2b)
## Turn the alpha to NA, and use an alpha-blended "forestgreen" for
## the NA values
# https://gist.githubusercontent.com/mages/5339689/raw/2aaa482dfbbecbfcb726525a3d81661f9d802a8e/add.alpha.R
# add.alpha("forestgreen", 0.5)
p2c <- vis_gene(
spe = spe,
sampleid = "151507",
cont_colors = rev(viridisLite::viridis(21, option = "magma")),
alpha = NA,
na_color = "#228B2280"
)
print(p2c)
## Visualize a continuous variable, in this case, the ratio of chrM
## gene expression compared to the total expression at the spot-level
p3 <- vis_gene(
spe = spe,
sampleid = "151507",
geneid = "expr_chrM_ratio"
)
print(p3)
## Visualize a gene using the rownames(spe)
p4 <- vis_gene(
spe = spe,
sampleid = "151507",
geneid = rownames(spe)[which(rowData(spe)$gene_name == "MOBP")]
)
print(p4)
## Repeat without auto-cropping the image
p5 <- vis_gene(
spe = spe,
sampleid = "151507",
geneid = rownames(spe)[which(rowData(spe)$gene_name == "MOBP")],
auto_crop = FALSE
)
print(p5)
# Define several markers for white matter
white_matter_genes <- c(
"ENSG00000197971", "ENSG00000131095", "ENSG00000123560",
"ENSG00000171885"
)
## Plot all white matter markers at once using the Z-score combination
## method
p6 <- vis_gene(
spe = spe,
sampleid = "151507",
geneid = white_matter_genes,
multi_gene_method = "z_score"
)
print(p6)
## Plot all white matter markers at once using the sparsity combination
## method
p7 <- vis_gene(
spe = spe,
sampleid = "151507",
geneid = white_matter_genes,
multi_gene_method = "sparsity"
)
print(p7)
## Plot all white matter markers at once using the PCA combination
## method
p8 <- vis_gene(
spe = spe,
sampleid = "151507",
geneid = white_matter_genes,
multi_gene_method = "pca"
)
print(p8)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.