plotCoverage: Plot read coverage across a genomic region

View source: R/wiggleplotr.R

plotCoverageR Documentation

Plot read coverage across a genomic region


Also supports rescaling introns to constant length. Extracts read coverage from bigWig files with extractCoverageData and plots it with plotCoverageData. Custom visualisations can be created by modifying the plotCoverageData function. Does not work on Windows, because rtracklayer cannot read BigWig files on Windows.


  cdss = NULL,
  transcript_annotations = NULL,
  rescale_introns = TRUE,
  new_intron_length = 50,
  flanking_length = c(50, 50),
  plot_fraction = 0.1,
  heights = c(0.75, 0.25),
  alpha = 1,
  fill_palette = c("#a1dab4", "#41b6c4", "#225ea8"),
  mean_only = TRUE,
  connect_exons = TRUE,
  transcript_label = TRUE,
  return_subplots_list = FALSE,
  region_coords = NULL,
  coverage_type = "area",
  show_legend = FALSE



list of GRanges objects, each object containing exons for one transcript. The list must have names that correspond to transcript_id column in transript_annotations data.frame.


list of GRanges objects, each object containing the coding regions (CDS) of a single transcript. The list must have names that correspond to transcript_id column in transript_annotations data.frame. If cdss is not specified then exons list will be used for both arguments. (default: NULL).


Data frame with at least three columns: transcript_id, gene_name, strand. Used to construct transcript labels. (default: NULL)


data.frame with the metadata for the bigWig read coverage files. Must contain the following columns:

  • sample_id - unique id for each sample.

  • track_id - if multiple samples (bigWig files) have the same track_id they will be overlayed on the same plot, track_id is also used as the facet label on the right.

  • bigWig - path to the bigWig file.

  • scaling_factor - normalisation factor for each sample, useful if different samples sequenced to different depth and bigWig files not normalised for that.

  • colour_group - additional column to group samples into, is used as the colour of the coverage track.


Specifies if the introns should be scaled to fixed length or not. (default: TRUE)


length (bp) of introns after scaling. (default: 50)


Lengths of the flanking regions upstream and downstream of the gene. (default: c(50,50))


Size of the random sub-sample of points used to plot coverage (between 0 and 1). Smaller values make plotting significantly faster. (default: 0.1)


Specifies the proportion of the height that is dedicated to coverage plots (first value) relative to transcript annotations (second value). (default: c(0.75,0.25))


Transparency (alpha) value for the read coverage tracks. Useful to set to something < 1 when overlaying multiple tracks (see track_id). (default: 1)


Vector of fill colours used for the coverage tracks. Length must be equal to the number of unique values in track_data$colour_group column.


Plot only mean coverage within each combination of track_id and colour_group values. Useful for example for plotting mean coverage stratified by genotype (which is specified in the colour_group column) (default: TRUE).


Print lines that connect exons together. Set to FALSE when plotting peaks (default: TRUE).


If TRUE then transcript labels are printed above each transcript. (default: TRUE).


Instead of a joint plot return a list of subplots that can be joined together manually.


Start and end coordinates of the region to plot, overrides flanking_length parameter.


Specifies if the read coverage is represented by either 'line', 'area' or 'both'. The 'both' option tends to give better results for wide regions. (default: area).


display legend for the colour_group next to the read coverage plot (default: FALSE).


Either object from cow_plot::plot_grid() function or a list of subplots (if return_subplots_list == TRUE)


sample_data = dplyr::data_frame(sample_id = c("aipt_A", "aipt_C", "bima_A", "bima_C"), 
    condition = factor(c("Naive", "LPS", "Naive", "LPS"), levels = c("Naive", "LPS")), 
    scaling_factor = 1) %>%
    dplyr::mutate(bigWig = system.file("extdata",  paste0(sample_id, ""), package = "wiggleplotr"))

track_data = dplyr::mutate(sample_data, track_id = condition, colour_group = condition)

selected_transcripts = c("ENST00000438495", "ENST00000392477") #Plot only two transcripts of the gens
## Not run: 
plotCoverage(ncoa7_exons[selected_transcripts], ncoa7_cdss[selected_transcripts], 
   ncoa7_metadata, track_data, 
   heights = c(2,1), fill_palette = getGenotypePalette())

## End(Not run)

kauralasoo/wiggleplotr documentation built on July 4, 2022, 11:43 a.m.