metadataPlot: Colour shade a 2-dimensional reduction / embedding based on...

Description Usage Arguments Details Value Author(s) Examples

View source: R/metadataPlot.R

Description

Colour shade a 2-dimensional reduction / embedding based on metadata, typically contained within a SingleCellExperiment object.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
metadataPlot(
  indata,
  meta = NULL,
  reducedDim = "UMAP",
  dimColnames = c("UMAP1", "UMAP2"),
  colby = NULL,
  colkey = NULL,
  pointSize = 0.5,
  legendPosition = "right",
  legendLabSize = 12,
  legendIconSize = 5,
  xlim = NULL,
  ylim = NULL,
  celllab = NULL,
  labSize = 3,
  drawConnectors = TRUE,
  widthConnectors = 0.5,
  colConnectors = "black",
  xlab = dimColnames[1],
  xlabAngle = 0,
  xlabhjust = 0.5,
  xlabvjust = 0.5,
  ylab = dimColnames[2],
  ylabAngle = 0,
  ylabhjust = 0.5,
  ylabvjust = 0.5,
  axisLabSize = 16,
  title = "Metadata plot",
  subtitle = "",
  caption = ifelse(is(indata, "SingleCellExperiment"), paste0("Total cells, ",
    nrow(as.data.frame(reducedDim(indata, reducedDim)))), paste0("Total cells, ",
    nrow(meta))),
  titleLabSize = 16,
  subtitleLabSize = 12,
  captionLabSize = 12,
  hline = NULL,
  hlineType = "longdash",
  hlineCol = "black",
  hlineWidth = 0.4,
  vline = NULL,
  vlineType = "longdash",
  vlineCol = "black",
  vlineWidth = 0.4,
  gridlines.major = TRUE,
  gridlines.minor = TRUE,
  borderWidth = 0.8,
  borderColour = "black"
)

Arguments

indata

A data-frame or matrix, or SingleCellExperiment object. If a data-frame or matrix, columns named in dimColnames will be extracted from the data and used to generate the plot. If a SingleCellExperiment object, a reduction named by reducedDim will be taken from your object and used to generate the plot, again using columns whose names are specified in dimColnames.

meta

If 'indata' is a non-SingleCellExperiment object, 'meta' must be activated and relate to a data-frame of metadata that aligns with the rows of indata, and that also contains a column name specified by colby.

reducedDim

A reduced dimensional embedding stored within indata, e.g., PCA or UMAP.

dimColnames

The column names of the dimensions to use.

colby

If NULL, all points will be coloured differently. If not NULL, the value is assumed to be a column name in metadata(indata) relating to some grouping / categorical variable.

colkey

Vector of name-value pairs relating to value passed to 'col', e.g., c(A='forestgreen', B='gold').

pointSize

Size of plotted points.

legendPosition

Position of legend ('top', 'bottom', 'left', 'right', 'none').

legendLabSize

Size of plot legend text.

legendIconSize

Size of plot legend icons / symbols.

xlim

Limits of the x-axis.

ylim

Limits of the y-axis.

celllab

A vector containing any cells that the user wishes to label in the plot.

labSize

Size of labels.

drawConnectors

Logical, indicating whether or not to connect plot labels to their corresponding points by line connectors.

widthConnectors

Line width of connectors.

colConnectors

Line colour of connectors.

xlab

Label for x-axis.

xlabAngle

Rotation angle of x-axis labels.

xlabhjust

Horizontal adjustment of x-axis labels.

xlabvjust

Vertical adjustment of x-axis labels.

ylab

Label for y-axis.

ylabAngle

Rotation angle of y-axis labels.

ylabhjust

Horizontal adjustment of y-axis labels.

ylabvjust

Vertical adjustment of y-axis labels.

axisLabSize

Size of x- and y-axis labels.

title

Plot title.

subtitle

Plot subtitle.

caption

Plot caption.

titleLabSize

Size of plot title.

subtitleLabSize

Size of plot subtitle.

captionLabSize

Size of plot caption.

hline

Draw one or more horizontal lines passing through this/these values on y-axis. For single values, only a single numerical value is necessary. For multiple lines, pass these as a vector, e.g., c(60,90).

hlineType

Line type for hline ('blank', 'solid', 'dashed', 'dotted', 'dotdash', 'longdash', 'twodash').

hlineCol

Colour of hline.

hlineWidth

Width of hline.

vline

Draw one or more vertical lines passing through this/these values on x-axis. For single values, only a single numerical value is necessary. For multiple lines, pass these as a vector, e.g., c(60,90).

vlineType

Line type for vline ('blank', 'solid', 'dashed', 'dotted', 'dotdash', 'longdash', 'twodash').

vlineCol

Colour of vline.

vlineWidth

Width of vline.

gridlines.major

Logical, indicating whether or not to draw major gridlines.

gridlines.minor

Logical, indicating whether or not to draw minor gridlines.

borderWidth

Width of the border on the x and y axes.

borderColour

Colour of the border on the x and y axes.

Details

Colour shade a 2-dimensional reduction / embedding based on metadata, typically contained within a SingleCellExperiment object.

Value

A ggplot2 object.

Author(s)

Kevin Blighe <kevin@clinicalbioinformatics.co.uk>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# create random data that follows a negative binomial
mat <- jitter(matrix(
  MASS::rnegbin(rexp(1000, rate=.1), theta = 4.5),
  ncol = 20))
colnames(mat) <- paste0('CD', 1:ncol(mat))
rownames(mat) <- paste0('cell', 1:nrow(mat))

u <- umap::umap(mat)$layout
colnames(u) <- c('UMAP1','UMAP2')
rownames(u) <- rownames(mat)

metadata <- data.frame(
  group = c(rep('PB1', 25), rep('PB2', 25)),
  row.names = rownames(u))

metadataPlot(u, meta = metadata, colby = 'group')

kevinblighe/scToolkit documentation built on Sept. 25, 2021, 11:29 p.m.