Introduction to plotgardener

Nicole Kramer, Eric S. Davis, Craig Wenger, Sarah Parker, Erika Deoudes, Michael Love, Douglas H. Phanstiel

Overview

plotgardener is a coordinate-based, genomic visualization package for R. Using grid graphics, plotgardener empowers users to programmatically and flexibly generate multi-panel figures. Tailored for genomics for a variety of genomic assemblies, plotgardener allows users to visualize large, complex genomic datasets while providing exquisite control over the arrangement of plots.

plotgardener functions can be grouped into the following categories:

Functions for creating plotgardener page layouts, drawing, showing, and hiding guides, as well as placing plots on the page. See The plotgardener Page

Functions for quickly reading in large biological datasets. See Reading Data for plotgardener

Contains genomic plotting functions, functions for placing ggplots and base plots, as well as functions for drawing simple shapes. See Plotting Multi-omic Data

Enables users to add annotations to their plots, such as legends, axes, and scales. See Plot Annotations

Functions that display plotgardener properties or operate on other plotgardener functions, or constructors for plotgardener objects. See plotgardener Meta Functions

This vignette provides a quick start guide for utilizing plotgardener. For in-depth demonstrations of plotgardener’s key features, see the additional articles. For detailed usage of each function, see the function-specific reference examples with ?function() (e.g. ?plotPairs()).

All the data included in this vignette can be found in the supplementary package plotgardenerData.

Quick plotting

plotgardener plotting functions contain 4 types of arguments:

  1. Data reading argument (data)

  2. Genomic locus arguments (chrom, chromstart, chromend, assembly)

  3. Placement arguments (x, y, width, height, just, default.units, …) that define where each plot resides on a page

  4. Attribute arguments that affect the data being plotted or the style of the plot (norm, fill, fontcolor, …) that vary between functions

The quickest way to plot data is to omit the placement arguments. This will generate a plotgardener plot that fills up the entire graphics window and cannot be annotated. These plots are only meant to be used for quick genomic data inspection and not as final plotgardener plots. The only arguments that are required are the data arguments and locus arguments. The examples below show how to quickly plot different types of genomic data with plot defaults and included data types. To use your own data, replace the data argument with either a path to the file or an R object as described above.

Hi-C matrices

Signal tracks

Gene tracks

GWAS Manhattan plots

Plotting and annotating on the plotgardener page

To build complex, multi-panel plotgardener figures with annotations, we must:

  1. Create a plotgardener coordinate page with pageCreate().
pageCreate(width = 3.25, height = 3.25, default.units = "inches")

  1. Provide values for the placement arguments (x, y, width, height, just, default.units) in plotting functions and save the output of the plotting function.
data("IMR90_HiC_10kb")
hicPlot <- plotHicSquare(
    data = IMR90_HiC_10kb,
    chrom = "chr21", chromstart = 28000000, chromend = 30300000,
    assembly = "hg19",
    x = 0.25, y = 0.25, width = 2.5, height = 2.5, default.units = "inches"
)

  1. Annotate plotgardener plot objects by passing them into the plot argument of annotation functions.
annoHeatmapLegend(
    plot = hicPlot,
    x = 2.85, y = 0.25, width = 0.1, height = 1.25, default.units = "inches"
)

annoGenomeLabel(
    plot = hicPlot,
    x = 0.25, y = 2.75, width = 2.5, height = 0.25, default.units = "inches"
)

For more information about how to place plots and annotations on a plotgardener page, check out the section Working with plot objects.

Exporting plots

When a plotgardener plot is ready to be saved and exported, we can first remove all page guides that were made with pageCreate():

pageGuideHide()

We can then either use the Export toggle in the RStudio plot panel, or save the plot within our R code as follows:

pdf(width = 3.25, height = 3.25)

pageCreate(width = 3.25, height = 3.25, default.units = "inches")
data("IMR90_HiC_10kb")
hicPlot <- plotHicSquare(
    data = IMR90_HiC_10kb,
    chrom = "chr21", chromstart = 28000000, chromend = 30300000,
    assembly = "hg19",
    x = 0.25, y = 0.25, width = 2.5, height = 2.5, default.units = "inches"
)
annoHeatmapLegend(
    plot = hicPlot,
    x = 2.85, y = 0.25, width = 0.1, height = 1.25, default.units = "inches"
)

annoGenomeLabel(
    plot = hicPlot,
    x = 0.25, y = 2.75, width = 2.5, height = 0.25, default.units = "inches"
)
pageGuideHide()

dev.off()

For more detailed usage and examples, please refer to the other available vignettes.

Future Directions

We still have many ideas to add for a second version of plotgardener including, but not limited to: grammar of graphics style plot arguments and plot building, templates, themes, and multi-plotting functions. If you have suggestions for ways we can improve plotgardener, please let us know!

Session Info

sessionInfo()
## R version 4.1.2 (2021-11-01)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.4 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.14-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.14-bioc/R/lib/libRlapack.so
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_GB              LC_COLLATE=C              
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats4    grid      stats     graphics  grDevices utils     datasets 
## [8] methods   base     
## 
## other attached packages:
##  [1] org.Hs.eg.db_3.14.0                    
##  [2] TxDb.Hsapiens.UCSC.hg19.knownGene_3.2.2
##  [3] GenomicFeatures_1.46.5                 
##  [4] AnnotationDbi_1.56.2                   
##  [5] Biobase_2.54.0                         
##  [6] GenomicRanges_1.46.1                   
##  [7] GenomeInfoDb_1.30.1                    
##  [8] IRanges_2.28.0                         
##  [9] S4Vectors_0.32.3                       
## [10] BiocGenerics_0.40.0                    
## [11] plotgardenerData_1.0.0                 
## [12] plotgardener_1.0.17                    
## 
## loaded via a namespace (and not attached):
##  [1] bitops_1.0-7                matrixStats_0.61.0         
##  [3] bit64_4.0.5                 filelock_1.0.2             
##  [5] RColorBrewer_1.1-2          progress_1.2.2             
##  [7] httr_1.4.2                  tools_4.1.2                
##  [9] bslib_0.3.1                 utf8_1.2.2                 
## [11] R6_2.5.1                    DBI_1.1.2                  
## [13] colorspace_2.0-3            prettyunits_1.1.1          
## [15] tidyselect_1.1.2            bit_4.0.4                  
## [17] curl_4.3.2                  compiler_4.1.2             
## [19] cli_3.2.0                   xml2_1.3.3                 
## [21] DelayedArray_0.20.0         rtracklayer_1.54.0         
## [23] sass_0.4.0                  scales_1.1.1               
## [25] rappdirs_0.3.3              stringr_1.4.0              
## [27] digest_0.6.29               Rsamtools_2.10.0           
## [29] yulab.utils_0.0.4           rmarkdown_2.13             
## [31] XVector_0.34.0              pkgconfig_2.0.3            
## [33] htmltools_0.5.2             MatrixGenerics_1.6.0       
## [35] dbplyr_2.1.1                fastmap_1.1.0              
## [37] highr_0.9                   rlang_1.0.2                
## [39] RSQLite_2.2.10              gridGraphics_0.5-1         
## [41] jquerylib_0.1.4             BiocIO_1.4.0               
## [43] generics_0.1.2              jsonlite_1.8.0             
## [45] BiocParallel_1.28.3         dplyr_1.0.8                
## [47] RCurl_1.98-1.6              magrittr_2.0.2             
## [49] ggplotify_0.1.0             GenomeInfoDbData_1.2.7     
## [51] Matrix_1.4-0                Rcpp_1.0.8.2               
## [53] munsell_0.5.0               fansi_1.0.2                
## [55] lifecycle_1.0.1             stringi_1.7.6              
## [57] yaml_2.3.5                  SummarizedExperiment_1.24.0
## [59] zlibbioc_1.40.0             BiocFileCache_2.2.1        
## [61] blob_1.2.2                  parallel_4.1.2             
## [63] crayon_1.5.0                lattice_0.20-45            
## [65] Biostrings_2.62.0           hms_1.1.1                  
## [67] KEGGREST_1.34.0             knitr_1.37                 
## [69] pillar_1.7.0                rjson_0.2.21               
## [71] biomaRt_2.50.3              strawr_0.0.9               
## [73] XML_3.99-0.9                glue_1.6.2                 
## [75] evaluate_0.15               data.table_1.14.2          
## [77] vctrs_0.3.8                 png_0.1-7                  
## [79] gtable_0.3.0                purrr_0.3.4                
## [81] assertthat_0.2.1            cachem_1.0.6               
## [83] ggplot2_3.3.5               xfun_0.30                  
## [85] restfulr_0.0.13             tibble_3.1.6               
## [87] GenomicAlignments_1.30.0    plyranges_1.14.0           
## [89] memoise_2.0.1               ellipsis_0.3.2