plot_annotation: Plot the number of regions per annotation

View source: R/visualize.R

plot_annotationR Documentation

Plot the number of regions per annotation

Description

Given a GRanges of annotated regions, plot the number of regions with the corresponding genomic annotations used in annotation_order. If a region is annotated to multiple annotations of the same annot.type, the region will only be counted once in the corresponding bar plot. For example, if a region were annotated to multiple exons, it would only count once toward the exon bar in the plot, but if it were annotated to an exon and an intron, it would count towards both.

Usage

plot_annotation(
  annotated_regions,
  annotated_random,
  annotation_order = NULL,
  plot_title,
  x_label,
  y_label,
  quiet = FALSE
)

Arguments

annotated_regions

The GRanges result of annotate_regions().

annotated_random

The GRanges result of annotate_regions() on the randomized regions created from randomize_regions().

annotation_order

A character vector which doubles as the subset of annotations desired for the plot as well as the ordering. If NULL, all annotations are displayed.

plot_title

A string used for the title of the plot. If missing, no title is displayed.

x_label

A string used for the x-axis label. If missing, no x-axis label is displayed.

y_label

A string used for the y-axis label. If missing, no y-axis label is displayed.

quiet

Print progress messages (FALSE) or not (TRUE).

Value

A ggplot object which can be viewed by calling it, saved with ggplot2::ggsave, or edited.

Examples

   ########################################################################
   # An example of ChIP-seq peaks with signalValue used for score

   # Get premade CpG annotations
   data('annotations', package = 'annotatr')

   chip_bed = system.file('extdata', 'Gm12878_Stat3_chr2.bed.gz', package = 'annotatr')
   chip_regions = read_regions(con = chip_bed, genome = 'hg19')

   chip_rnd = randomize_regions(regions = chip_regions)

   chip_annots = annotate_regions(
       regions = chip_regions,
       annotations = annotations,
       ignore.strand = TRUE)

   chip_rnd_annots = annotate_regions(
       regions = chip_rnd,
       annotations = annotations,
       ignore.strand = TRUE)

   annots_order = c(
       'hg19_cpg_islands',
       'hg19_cpg_shores')

   p_annots = plot_annotation(annotated_regions = chip_annots,
       annotation_order = annots_order)
   p_annots_rnd = plot_annotation(annotated_regions = chip_annots,
       annotated_random = chip_rnd_annots, annotation_order = annots_order)


rcavalcante/annotatr documentation built on March 25, 2023, 9:51 a.m.