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

View source: R/dimreduc.R

fortify.DimReducR 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 DimReduc objects in ggplot() (see examples)

Usage

## S3 method for class 'DimReduc'
fortify(model, data, na.rm = FALSE, ...)

Arguments

model

A DimReduc object

data

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

na.rm

Remove values with NAs

...

Ignored

Details

fortify.DimReduc() generates a data frame based on the cell embeddings. Automatically creates a column for cell names (“cell”). Also 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

  • cell embeddings

  • additional meta data provided by data

Value

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

See Also

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

Visualize Dimensional Reductions: autolayer.DimReduc(), autoplot.DimReduc()

Examples

data("pbmc_small")
tsne <- pbmc_small[["tsne"]]
md <- FetchData(pbmc_small, vars = c("ident", "MS4A1"))

# Create a data frame for `ggplot()`
df <- fortify(tsne, data = md)
head(df)
ggplot(df, mapping = aes(x = tSNE_1, y = tSNE_2, color = ident)) +
  geom_point()

# Use a `DimReduc` directly in `ggplot()`
ggplot(tsne, mapping = aes(x = tSNE_1, y = tSNE_2, color = MS4A1), md) +
  geom_point()


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