vizAllTopics: Visualize all topic proportions across pixels with...

View source: R/plot.R

vizAllTopicsR Documentation

Visualize all topic proportions across pixels with scatterpie

Description

Note: visualizes all cell-types in theta at once (could be individual cell-types or cell-type-clusters) so for accuracy of the proportions of each cell-type in a pixel, the row (pixel) should sum to 1.

Usage

vizAllTopics(
  theta,
  pos,
  topicOrder = seq(ncol(theta)),
  topicCols = rainbow(ncol(theta)),
  groups = NA,
  group_cols = NA,
  r = max(0.4, max(pos)/nrow(pos) * 4),
  lwd = 0.01,
  showLegend = TRUE,
  plotTitle = NA,
  overlay = NA
)

Arguments

theta

document (pixel) x cell-type proportion matrix

pos

position of pixels, as data.frame with x and y columns

topicOrder

order of topics in theta to visualize as a numeric vector and same length as topicCols (default: seq(ncol(theta)))

topicCols

Vector of colors for each of the cell-types to be visualized. Same length and order as topicOrder (default: rainbow(ncol(theta)))

groups

Indicates color of the scatterpie strokes (borders) with the goal of coloring them by their assigned group. This can be a vector or factor indicating the group of each pixel. Needs to be in the same order as the pixel rows in "theta" (default: NA)

group_cols

Color labels for the groups. Can be a vector or factor. (default: NA)

r

Radius of the scatterpie circles. Adjust based on positions of pixels (default: max(0.4, max(pos)/nrow(pos)*4))

lwd

Width of lines of the pie charts. Increasing helps visualize group_cols if being used (default: 0.01)

showLegend

Boolean to show the legend indicating cell-types and their color

plotTitle

add title to the resulting plot (default: NA)

overlay

raster image of an H&E tissue (for example) to plot the scatterpies on top of (default: NA)

Value

a plot of scatterpies, where each scatterpie represents a pixel in space based on the x,y coordinates and the components represent the proportion of each cell-type at that pixel.

Examples

data(mOB)
pos <- mOB$pos
cd <- mOB$counts
annot <- mOB$annot
counts <- cleanCounts(cd, min.lib.size = 100)
corpus <- restrictCorpus(counts, removeAbove=1.0, removeBelow = 0.05)
ldas <- fitLDA(t(as.matrix(corpus)), Ks = 3)
optLDA <- optimalModel(models = ldas, opt = 3)
results <- getBetaTheta(optLDA, perc.filt = 0.05, betaScale = 1000)
deconProp <- results$theta
vizAllTopics(deconProp,pos, groups = annot, group_cols = rainbow(length(levels(annot))), r=0.4)


JEFworks-Lab/STdeconvolve documentation built on Nov. 14, 2024, 7:24 p.m.