Skip to main content
v2026.11,986 entries · CC-BY 4.0

Gviz in R: How to Plot Genomic Tracks with Bioconductor

Gviz is the Bioconductor R package for plotting genomic tracks: install it, build a track stack step by step, read the output and fix common errors.

Written and maintained by CASRAI Editorial Board

Published

On this page

Gviz is an R package from Bioconductor that draws data and annotation along genomic coordinates: you build one track object per data type (a coordinate axis, a chromosome ideogram, gene models, numeric signal, aligned reads, sequence) and pass the list to plotTracks(), which stacks them into a single figure. It is a different tool from Graphviz, the graph-drawing program that shares part of its name. Version 1.56.0 is the release listed for Bioconductor 3.23, and it installs through BiocManager.

What Gviz is used for in research

The Bioconductor package page describes Gviz as software for plotting data and annotation information along genomic coordinates, and it files the package under the Microarray, Sequencing, Software and Visualization categories. In practice that means one region of a genome shown as aligned layers: where genes and their exons sit, where a signal such as read coverage or a methylation value rises, which regions are annotated as features of interest, and what the underlying sequence is. Because the figure is built in R from objects you can inspect, the code that produced it can be kept next to the analysis, which supports the computational reproducibility of a figure as well as of a result.

Gviz can fetch annotation for you. The package page states that it uses the biomaRt and rtracklayer packages to run live annotation queries against Ensembl and UCSC, and it draws with the grid graphics system. It can also build tracks from annotation you already hold locally: the user guide shows gene tracks made from TxDb objects (the GenomicFeatures package) and EnsDb objects (the ensembldb package), numeric tracks made from bedGraph and BAM files, and sequence tracks made from a BSgenome package. The package is licensed Artistic-2.0, which makes it open-source software that a research group can run, cite and inspect without a licence fee.

Track classes at a glance

The user guide, titled The Gviz User Guide, organises the package around track classes. The data table below pairs each class with the input the guide builds it from; the choice of class follows from the kind of data you have, not from the look you want.

How to install or access Gviz

Install Gviz from Bioconductor, not from the default CRAN repository. The package page gives this two-line recipe, which first installs the BiocManager helper if it is missing:

if (!require("BiocManager", quietly = TRUE))     install.packages("BiocManager")  BiocManager::install("Gviz")

Check your R version first. The package page lists R 4.3 or later as a dependency for the current release, alongside the methods, S4Vectors, IRanges, GenomicRanges and grid packages. The Bioconductor install page states that release 3.23 works with R 4.6.0, so check that your R installation matches the Bioconductor release you are installing. The package imports a long list of Bioconductor packages, among them rtracklayer, biomaRt, GenomicFeatures, ensembldb, BSgenome, Biostrings, Rsamtools and GenomicAlignments, and BiocManager installs these for you.

The source code is public on GitHub at ivanek/Gviz, where the issue tracker is the place to report bugs. The package page names Robert Ivanek as maintainer and lists the citation authors as Hahne, Durinck, Ivanek and colleagues; the package DOI is 10.18129/B9.bioc.Gviz. From inside R, citation("Gviz") returns the formal citation, which is the form to use in a methods section.

How to plot genomic tracks with Gviz step by step

The walkthrough below follows the example data that ship with the package, so it runs without any files of your own. Each step is taken from The Gviz User Guide.

  1. Load the packages and the example CpG island data. The data set carries its genome build and chromosome, which you read back out for later steps:
    library(Gviz) library(GenomicRanges) data(cpgIslands) chr = as.character(unique(seqnames(cpgIslands))) gen = genome(cpgIslands)
  2. Make an annotation track from the ranges and draw it:
    atrack = AnnotationTrack(cpgIslands, name = "CpG") plotTracks(atrack)
  3. Add a genomic axis. A GenomeAxisTrack needs no data because it is always relative to the other tracks; you pass the tracks to plotTracks() as a list:
    gtrack = GenomeAxisTrack() plotTracks(list(gtrack, atrack))
  4. Add a chromosome ideogram. This step needs an internet connection:
    itrack = IdeogramTrack(genome = gen, chromosome = chr) plotTracks(list(itrack, gtrack, atrack))
  5. Add gene models from the bundled example data and plot all four tracks:
    data(geneModels) grtrack = GeneRegionTrack(geneModels, genome = gen, chromosome = chr, name = "Gene Model") plotTracks(list(itrack, gtrack, atrack, grtrack))
  6. Zoom to a window by giving genomic coordinates to plotTracks():
    plotTracks(list(itrack, gtrack, atrack, grtrack), from = 26700000, to = 26750000)

The guide also shows relative zooming with extend.left and extend.right: a value between -1 and 1 is read as a zoom factor. The guide’s example combines both: extend.left = 0.5, extend.right = 1000000. Setting col = NULL removes the borders around features.

Using your own data

To replace the example data, pick the track class that matches your input from the data table. Numeric signal is the job of DataTrack; the guide builds one from a bedGraph file with DataTrack(range = bgFile, genome = "hg19", type = "l") and notes that the same range argument accepts a BAM file. The type argument selects the drawing style, and the guide uses values such as “histogram”, “boxplot”, “heatmap”, “confint”, “smooth”, “l” (line), “p” (points), “b” (both) and “a” (group averages). The arguments groups, window, windowSize, aggregation and aggregateGroups control grouping and summarising. For gene structure use GeneRegionTrack, built from ranges such as the bundled gene models, a TxDb or an EnsDb; use SequenceTrack with a BSgenome package such as BSgenome.Hsapiens.UCSC.hg19 for the nucleotide sequence; and use AlignmentsTrack for aligned reads, which the guide displays as “coverage”, “sashimi” or “pileup” types.

How to read the output

A Gviz figure is a vertical stack of tracks that share one horizontal genomic coordinate axis. Reading it is a matter of reading down a single position: whatever sits in the same column in every track refers to the same stretch of the chromosome. Three habits make the figure trustworthy.

  • Read the axis first. The GenomeAxisTrack carries the coordinates, and the plotted window is whatever you set with from and to (or the extent of the data when you set neither). Report the window and the genome build with the figure, because coordinates mean nothing without the build; the examples here carry genome information for exactly this reason.
  • Match the track to its meaning. An AnnotationTrack draws features as blocks over the coordinates, a GeneRegionTrack draws gene or transcript models, and a DataTrack draws values. A block in an annotation track is a region with a label, not a measured quantity, whereas the height or colour in a data track is a value whose summarising rule (for example the window, windowSize and aggregation settings) belongs in the figure legend.
  • Know what is drawn. Only one chromosome is drawn per track at a time, so a figure showing a region is not a genome-wide view. For several chromosomes the user guide has a section on composite plots.

When the figure goes into a manuscript, state the Gviz and Bioconductor versions with the code, since both the package and its dependencies change between releases. Pairing the script with a documented review step, as described in the code review of research software entry, helps others check that the plot matches the data it claims to show.

Troubleshooting Gviz

Chromosome names are rejected

By default Gviz enforces UCSC-style chromosome names, which must start with “chr”, through the global option ucscChromosomeNames. Data that uses Ensembl-style names such as “1” instead of “chr1” therefore fails the check. Either rename the sequences to the UCSC form or, when you know your names are consistent across all tracks, switch the check off:

options(ucscChromosomeNames = FALSE)

The ideogram step fails

The user guide notes that IdeogramTrack() needs an internet connection, because it fetches chromosome data online. If you work offline or behind a firewall, leave the ideogram out and plot the remaining tracks.

The plot shows the wrong chromosome or nothing

Each track holds a single active chromosome. If the data covers several chromosomes, set the one you want with chromosome(obj) = "chrId", replacing chrId with your chromosome name.

An install or load error

Confirm that R meets the version in the package dependencies (R 4.3 or later for the current release) and that you installed through BiocManager::install(). Package-specific problems that these checks do not explain can be reported on the issue tracker at github.com/ivanek/Gviz, and the user guide and reference manual linked in the sources list the arguments of every function.

Free alternatives to Gviz

Gviz is scripted and publication-oriented. Other free tools approach the same task from a graphical or browser-based direction, or with a different R plotting style. The table lists each tool with what its own documentation says about it.

Tool What its documentation says Where it runs
Integrative Genomics Viewer (IGV) A high-performance, interactive tool for visual exploration of genomic data; open source under the MIT licence Java desktop application; IGV-Web in a browser; igv.js for embedding in web pages
UCSC Genome Browser Displays any requested portion of a genome at any scale with aligned annotation tracks; supports custom tracks and track hubs Web application
ggbio (Bioconductor) Extends the grammar of graphics for biological data, with detailed region views and genome-wide overviews such as ideograms and grand linear views R package
trackViewer (Bioconductor) Draws mapped reads with annotation as track layers for datasets such as ChIP-seq and RNA-seq, with a web interface for interactive tracks and lollipop plots R package with web interface

The practical difference is workflow. IGV and the UCSC Genome Browser are for exploring data interactively; Gviz, ggbio and trackViewer produce figures from code, so the same script regenerates the figure when the data changes. Which of the three R packages fits depends on whether you want Gviz’s track-object model, ggbio’s grammar-of-graphics model, or trackViewer’s read-and-lollipop focus. Projects that publish their analysis scripts generally follow the reproducible research practices that code-based plotting makes possible.

Sources

Data: Gviz track classes and the input each is built from

Compiled from the Bioconductor Gviz package page and The Gviz User Guide: each track class the guide documents for drawing a genomic region, the input the guide builds it from, and what it draws. Release 3.23, package version 1.56.0.

Period covered: Bioconductor 3.23.

Gviz track classes and the input each is built from
Track classInput it is built fromWhat it draws
GenomeAxisTrackNone: it adds a coordinate axis relative to the other tracksDraws the genomic coordinate axis
IdeogramTrackGenome build and chromosome name (needs internet)Shows the chromosome the plotted window belongs to
AnnotationTrackGenomic ranges, for example a GRanges object such as the cpgIslands exampleDraws annotated regions as features along the axis
GeneRegionTrackGene model ranges, or a TxDb (GenomicFeatures) or EnsDb (ensembldb) objectDraws gene and transcript structures
BiomartGeneRegionTrackA biomaRt query to EnsemblDraws gene models fetched live from Ensembl
DataTrackNumeric values over ranges, from a bedGraph file, a BAM file or ranges with dataDraws values as lines, points, histograms, boxplots, heatmaps and other types
SequenceTrackA BSgenome package such as BSgenome.Hsapiens.UCSC.hg19Shows the nucleotide sequence
AlignmentsTrackAligned sequencing readsShows coverage, sashimi or pileup views

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · full access

Ask about Gviz in R: How to Plot Genomic Tracks with Bioconductor

Full access: large monthly usage, up to 10 source passages behind each answer, and MCP and API access for Claude Code, Codex and other CLIs. Cancel any time.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →