Learn R Programming

ggalign (version 0.0.4)

align_gg: Create ggplot object with a customized data

Description

ggalign is just an alias of align_gg.

Usage

align_gg(
  mapping = aes(),
  size = NULL,
  free_guides = waiver(),
  free_spaces = waiver(),
  plot_data = waiver(),
  theme = waiver(),
  free_labs = waiver(),
  data = NULL,
  limits = TRUE,
  facet = TRUE,
  set_context = TRUE,
  order = NULL,
  name = NULL
)

ggalign( mapping = aes(), size = NULL, free_guides = waiver(), free_spaces = waiver(), plot_data = waiver(), theme = waiver(), free_labs = waiver(), data = NULL, limits = TRUE, facet = TRUE, set_context = TRUE, order = NULL, name = NULL )

Value

A AlignGG object.

Arguments

mapping

Additional default list of aesthetic mappings to use for plot.

size

Plot size, can be an unit object.

free_guides

Override the guides argument specified in the layout for a plot. Options include:

  • waiver(): inherits behavior from the layout.

  • NULL: no guide legends will be collected for the plot.

  • A string containing one or more of "t", "l", "b", and "r" indicates which side of guide legends should be collected for the plot..

free_spaces

A string with one or more of "t", "l", "b", and "r" indicating which border spaces should be removed. Defaults to waiver(), which inherits from the parent layout. If no parent, the default is NULL, meaning no spaces are removed.

plot_data

A function to transform plot data before rendering. Defaults to waiver(), which inherits from the parent layout. If no parent layout, the default is NULL, meaning the data won't be modified.

Used to modify the data after layout has been created, which should be a data frame, but before the data is handled of to the ggplot2 for rendering. Use this hook if the you needs change the default data for all geoms.

theme

Default plot theme: One of:

  • waiver(): will inherit from the parent layout.

  • NULL: Use the default theme.

  • theme(): will be added with the parent layout theme.

Note: The axis title and labels parallel to the layout axis will always be removed by default. For vertical stack layouts, this refers to the x-axis, and for horizontal stack layouts, this refers to the y-axis. If you want to display the axis title or labels, you should manually add theme() elements for the parallel axis title or labels.

free_labs

A string with one or more of "t", "l", "b", and "r" indicating which axis titles should be free from alignment. Defaults to waiver(), which inherits from the parent layout. If no parent layout, no axis titles will be aligned. If NULL, all axis titles will be aligned.

data

A matrix, data frame, or a simple vector. If an atomic vector is provided, it will be converted into a one-column matrix. When data = NULL, the internal layout data will be used by default. Additionally, data can be a function (including purrr-like lambdas), which will be applied to the layout data.

It is important to note that we consider the rows as the observations. It means the NROW(data) must return the same number with the specific layout axis (meaning the x-axis for vertical stack layout, or y-axis for horizontal stack layout).

  • heatmap_layout(): for column annotation, the layout data will be transposed before using (If data is a function, it will be applied with the transposed matrix). This is necessary because column annotation uses heatmap columns as observations, but we need rows.

  • stack_layout(): the layout data will be used as it is since we place all plots along a single axis.

limits

A boolean value indicates whether to set the layout limtis for the plot.

facet

A boolean value indicates whether to set the layout facet for the plot. If this is FALSE, limits will always be FALSE too.

set_context

A single boolean value indicates whether to set the active context to current plot. If TRUE, all subsequent ggplot elements will be added into this plot.

order

An single integer for the plot area order.

name

A string of the plot name. Used to switch the active context in hmanno() or stack_active().

ggplot2 specification

align_gg initializes a ggplot data and mapping.

align_gg() always applies a default mapping for the axis of the data index in the layout. This mapping is aes(y = .data$.y) for horizontal stack layout (including left and right heatmap annotation) and aes(x = .data$.x) for vertical stack layout (including top and bottom heatmap annotation).

For ggplot usage, matrix (including a simple vector) data is converted into a long-format data frame. The data in the underlying ggplot object will contain following columns:

  • .panel: the panel for current layout axis. It means x-axis for vertical stack layout, y-axis for horizontal stack layout.

  • .x or .y: the x or y coordinates

  • .row_names and .row_index: A factor of the row names and an integer of row index of the original matrix or data frame.

  • .column_names and .column_index: the column names and column index of the original matrix (only applicable if data is a matrix).

  • value: the actual matrix value (only applicable if data is a matrix).

In the case where the input data is already a data frame, three additional columns (.row_names, .row_index, and .panel) are added to the data frame.

If the data is inherit from heatmap_layout(), an additional column will be added.

  • .extra_panel: the panel information for column (left or right annotation) or row (top or bottom annotation).

Examples

Run this code
ggheatmap(matrix(rnorm(81), nrow = 9)) +
    hmanno("top") +
    ggalign() +
    geom_point(aes(y = value))

Run the code above in your browser using DataLab