plotTabset: Plot a tabset

View source: R/utils.R

plotTabsetR Documentation

Plot a tabset

Description

Plot a tabset of colData annotations of one or more SpatialExperiment objects over an image.

Usage

plotTabset(spe.list, img)

Arguments

spe.list

A named list of SpatialExperiment objects.

img

a raster object representing a bitmap image.

Value

None. Produces a tabset for rendering with rmarkdown.

Examples

    library(SpatialExperiment) 
    # create simulated data as described in the SpatialExperiment man page
    n <- 1000; ng <- 50; nc <- 20
    # sample xy-coordinates in [0,1]
    x <- runif(n)
    y <- runif(n)
    # assign each molecule to some gene-cell pair
    gs <- paste0("gene", seq(ng))
    cs <- paste0("cell", seq(nc))
    gene <- sample(gs, n, TRUE)
    cell <- sample(cs, n, TRUE)
    # construct data.frame of molecule coordinates
    df <- data.frame(gene, cell, x, y)
    
    # (assure gene & cell are factor so that
    # missing observations aren't dropped)
    df$gene <- factor(df$gene, gs)
    df$cell <- factor(df$cell, cs)
    
    # construct BumpyMatrix
    mol <- BumpyMatrix::splitAsBumpyMatrix(
        df[, c("x", "y")],
        row = df$gene, column = df$cell)
    
    # get count matrix
    y <- with(df, table(gene, cell))
    y <- as.matrix(unclass(y))
    
    # construct SpatialExperiment
    spe <- SpatialExperiment(assays = list(counts = y, molecules = mol))

    # add simulated cell centroids
    s <- cbind(x = runif(20), y = runif(20))    
    spatialCoords(spe) <- s 

    # add simulated cell type and cell cycle annotation
    ct <- c("ct1", "ct2", "ct3")
    cc <- c("G1", "G2", "S", "M") 
    spe$type <- sample(ct, ncol(spe), replace = TRUE)
    spe$cycle <- sample(cc, ncol(spe), replace = TRUE)

    # create an example image
    hgrid <- hcl(0, 80, seq(50, 80, 10))
    img <- as.raster(matrix(hgrid, nrow = 4, ncol = 5))

    # plotTabset
    spe.list <- list(myseg = spe)
    plotTabset(spe.list, img)  

ccb-hms/MerfishData documentation built on Aug. 19, 2022, 8:55 a.m.