Package 'ggseurat'

Title: ggplot2 Bindings for Seurat Objects
Description: Provides methods to allow Seurat objects to be utilized directly in the ggplot2 ecosystem.
Authors: Paul Hoffman [aut, cre]
Maintainer: Paul Hoffman <[email protected]>
License: MIT + file LICENSE
Version: 0.0.0.9002
Built: 2024-11-10 03:14:43 UTC
Source: https://github.com/mojaveazure/ggseurat

Help Index


ggseurat: ggplot2 Bindings for Seurat Objects

Description

Provides methods to allow Seurat objects to be utilized directly in the ggplot2 ecosystem.

Author(s)

Maintainer: Paul Hoffman [email protected] (ORCID)

See Also

Useful links:


Create a Layer to Add to ggplot Objects

Description

Generate a geom_violin layer to add to existing ggplot objects. The new plot data and aesthetics are stored at the geom level

Usage

## S3 method for class 'Assay'
autolayer(
  object,
  data = missing_arg(),
  features = NULL,
  layer = c("data", "scale.data", "counts"),
  na.rm = TRUE,
  show.legend = NA,
  ...
)

Arguments

object

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

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

...

Arguments passed to geom_violin

Details

The following aesthetics are mapped automatically and overwrite said aesthetics at the plot level if set:

  • x

  • y

  • fill

Value

A geom_violin layer to add to ggplot objects

See Also

ggplot2::autolayer(), ggplot2::geom_violin()

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

Examples

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

# Generate a plot using `autolayer()`

Create a Layer to Add to ggplot Objects

Description

Generate a geom_point layer to add to existing ggplot objects. The new plot data and aesthetics are stored at the geom level

Usage

## S3 method for class 'DimReduc'
autolayer(
  object,
  data = missing_arg(),
  dims = c(1L, 2L),
  na.rm = TRUE,
  show.legend = NA,
  ...
)

Arguments

object

A DimReduc object

data

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

dims

Dimensions for visualization

na.rm

Remove values with NAs

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

...

Arguments passed to geom_point

Details

The following aesthetics are mapped automatically and overwrite said aesthetics at the plot level if set:

  • x

  • y

  • color

Value

A geom_point layer to add to ggplot objects

See Also

ggplot2::autolayer(), ggplot2::geom_point()

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

Examples

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

# Generate a plot using `autolayer()`
ggplot() + autolayer(tsne)
ggplot() + autolayer(tsne, data = md)

Create a Plot for Assay Objects

Description

Generate a ggplot plot for Assay objects

Usage

## S3 method for class 'Assay'
autoplot(
  object,
  data = missing_arg(),
  features = NULL,
  layer = c("data", "scale.data", "counts"),
  na.rm = TRUE,
  show.legend = NA,
  ...
)

Arguments

object

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

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

...

Arguments passed to geom_violin

Details

The following aesthetics are mapped automatically:

  • x

  • y

  • fill

Value

A ggplot object

See Also

ggplot2::autoplot()

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

Examples

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

# Generate a plot using `autoplot()`

Create a Plot for DimReduc Objects

Description

Generate a ggplot plot for DimReduc objects

Usage

## S3 method for class 'DimReduc'
autoplot(
  object,
  data = missing_arg(),
  dims = c(1L, 2L),
  na.rm = TRUE,
  show.legend = NA,
  ...
)

Arguments

object

A DimReduc object

data

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

dims

Dimensions for visualization

na.rm

Remove values with NAs

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

...

Arguments passed to geom_point

Details

The following aesthetics are mapped automatically:

  • x

  • y

  • color

Value

A ggplot object

See Also

ggplot2::autoplot()

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

Examples

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

# Generate a plot using `autoplot()`
autoplot(tsne)
autoplot(tsne, data = md)

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 “SeuratProject”; 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()

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 “SeuratProject”; 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()

ggplot_build.Seurat

Description

ggplot_build.Seurat

Usage

## S3 method for class 'ggseurat'
ggplot_build(plot)

Arguments

plot

ggplot object

Value

A built ggplot ready for viewing

See Also

ggplot_build


Visualize Seurat objects

Description

Visualize Seurat objects

Usage

## S3 method for class 'Seurat'
ggplot(data = NULL, mapping = aes(), ..., environment = parent.frame())

Arguments

data

A Seurat object

mapping

Default list of aesthetic mappings to use for plot. If not specified, must be supplied in each layer added to the plot.

...

Other arguments passed on to methods. Not currently used.

environment

DEPRECATED. Used prior to tidy evaluation.

Value

A ggplot object

See Also

ggplot