Skip to contents

This function creates a coverage track visualization from various input types. It provides a flexible interface with support for grouping and multiple tracks.

Usage

ez_coverage(
  input,
  region,
  track_labels = NULL,
  type = c("area", "line", "heatmap"),
  group_var = NULL,
  color_by = c("group", "track"),
  colors = "steelblue",
  y_axis_style = c("none", "simple", "minmax", "full"),
  y_range = NULL,
  alpha = 0.5,
  bin_width = NULL,
  facet_label_position = c("top", "left"),
  border = FALSE,
  show_legend = FALSE,
  ...
)

Arguments

input

A GRanges object, data frame, character vector of file paths, or named list of data sources.

region

Genomic region to display (e.g., "chr1:1000000-2000000")

track_labels

Optional vector of track labels (used for character vector input)

type

Type of signal visualization: "line", "area", or "heatmap" (default: "area")

group_var

Column name for grouping data within a single data frame (default: NULL)

color_by

Whether colors distinguish "group" or "track" (default: "group")

colors

Color(s) for the coverage track. Can be a single color (e.g., "steelblue") or a vector of colors for multiple tracks/groups (e.g., c("blue", "orange", "green")). If fewer colors than tracks/groups are provided, colors will be recycled. Default is "steelblue".

y_axis_style

Y-axis style: "none", "simple", "minmax", or "full" (default: "none")

  • "none": No y-axis displayed

  • "simple": Shows y-range as [min - max] label at top-left

  • "minmax": Shows only min and max values on y-axis with ticks

  • "full": Full y-axis with all ticks and labels

y_range

Y-axis range limits (default: NULL)

alpha

Transparency (default: 0.5)

bin_width

Width of bins in base pairs (default: NULL)

facet_label_position

Position of facet labels: "top" or "left" (default: "top")

border

Logical. If TRUE, adds a black border around the plotting panel (default: FALSE)

show_legend

Logical. If TRUE, displays the legend (default: FALSE)

...

Additional arguments passed to geom_coverage

Value

A ggplot2 object

Examples

# From a GRanges object
library(GenomicRanges)
gr <- GRanges(
  seqnames = "chr1",
  ranges = IRanges(start = 1:100, end = 1:100),
  score = rnorm(100)
)
ez_coverage(gr, "chr1:1-100")
#> Error in dplyr::filter(input, seqnames == as.character(region_gr@seqnames),     start >= region_gr@start, end <= region_gr@end):  In argument: `start >= region_gr@start`.
#> Caused by error:
#> ! no slot of name "start" for this object of class "GRanges"

# Single data frame with grouping
df <- data.frame(
  seqnames = "chr1", start = 1:100, end = 1:100,
  score = rnorm(100), sample = rep(c("A", "B"), 50)
)
ez_coverage(df, "chr1:1-100", group_var = "sample", colors = c("blue", "orange"))
#> Error in dplyr::filter(input, seqnames == as.character(region_gr@seqnames),     start >= region_gr@start, end <= region_gr@end):  In argument: `start >= region_gr@start`.
#> Caused by error:
#> ! no slot of name "start" for this object of class "GRanges"