Skip to contents

Renders a nucleotide sequence track using one of two visual styles. Colors follow UCSC Genome Browser conventions by default (A = green, C = blue, G = gold, T = red, N = grey).

Usage

geom_sequence(
  mapping = NULL,
  data = NULL,
  stat = "identity",
  position = "identity",
  ...,
  style = c("text", "tile"),
  show_labels = TRUE,
  label_size = 3,
  label_color = "white",
  tile_height = 0.8,
  tile_width = 1,
  na.rm = TRUE,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping

Aesthetic mappings. Required: x (genomic position), label (nucleotide character). Optional: fill (nucleotide color), colour (tile border color, only used when style = "tile").

data

Dataset (default: NULL).

stat

Statistic to use (default: "identity").

position

Position adjustment (default: "identity").

...

Other arguments passed on to ggplot2::layer().

style

Character. Visual style for the sequence track:

  • "text" (default): bold, colored nucleotide letters with no background or border. Letter color is taken from the fill aesthetic.

  • "tile": colored background tiles with letters on top (controlled by show_labels and label_color).

show_labels

Logical. Whether to draw nucleotide letter labels. For style = "text", labels are always drawn when show_labels = TRUE. For style = "tile", labels are drawn on top of the colored tiles. Default: TRUE.

label_size

Numeric. Font size for nucleotide letters (in pt). Default: 3.

label_color

Character. Color of the nucleotide letter text, used only when style = "tile". For style = "text", letter color is taken from the fill aesthetic. Default: "white".

tile_height

Numeric (0–1). Height of each nucleotide tile as a proportion of the y-axis range. Only used when style = "tile". Default: 0.8.

tile_width

Numeric. Width of each nucleotide tile in data (genomic) units. Only used when style = "tile". Default: 1 (one base pair per tile).

na.rm

Logical. Silently remove NA values. Default: TRUE.

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. To include legend keys for all levels, even when no data exists, use TRUE. If NA, all levels are shown in legend, but unobserved levels are omitted.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. annotation_borders().

Value

A ggplot2 layer.

Examples

if (FALSE) { # \dontrun{
library(ggplot2)
df <- data.frame(
  position   = 1:10,
  nucleotide = c("A", "T", "G", "C", "A", "T", "G", "C", "N", "A"),
  fill       = c("#00A800", "#CC0000", "#CC9900", "#0000CC",
                 "#00A800", "#CC0000", "#CC9900", "#0000CC", "#999999", "#00A800")
)
ggplot(df, aes(x = position, label = nucleotide, fill = fill)) +
  geom_sequence() +
  ggplot2::scale_fill_identity()
} # }