fortify.Assay: Create a Data Frame Suitable for 'ggplot()'

View source: R/assay.R

fortify.AssayR Documentation

Create a Data Frame Suitable for ggplot()

Description

Generate a long-format data frame for ease of use with ggplot(); as a bonus, this method enables direct calling of Assay objects in ggplot() (see examples)

Usage

## S3 method for class 'Assay'
fortify(
  model,
  data,
  features = NULL,
  layer = c("data", "scale.data", "counts"),
  na.rm = FALSE,
  ...
)

Arguments

model

An Assay object

data

A data.frame (eg. from FetchData) with extra data for visualization

features

A vector of features to include in the fortified data; defaults to the variable features

layer

Name of layer to pull expression data for

na.rm

Remove values with NAs

...

Ignored

Details

fortify.Assay() generates a data frame based on the expression data stored in layer; automatically creates a column for cell names (“cell”). Also creates creates a column for identity classes (“ident”) if not present in data; the default identity class is \Sexpr[stage=render, results=rd]{ggseurat::.rd_ident()}; final column output order is:

  • cell

  • ident

  • expression data for features

  • additional meta data provided by data

Value

A long-format data frame for use with ggplot()

See Also

ggplot2::ggplot(), ggplot2::fortify()

Visualize Assay Expression Data: autolayer.Assay(), autoplot.Assay()

Examples

data("pbmc_small")
rna <- pbmc_small[["RNA"]]
md <- FetchData(pbmc_small, vars = "ident")

# Create a data frame for `ggplot()`
df <- fortify(rna, data = md)
head(df)
ggplot(df, mapping = aes(x = ident, y = PPBP, fill = ident)) +
  geom_violin()

# Use an `Assay` directly in `ggplot()`
ggplot(rna, mapping = aes(x = ident, y = GNLY, fill = ident), md) +
  geom_violin()


mojaveazure/ggseurat documentation built on Dec. 10, 2024, 12:05 a.m.