Beyond providing functions for plotting and arranging various genomic datasets, plotgardener also gives users the functionality to plot other elements within a plotgardener page layout:

Ideograms

In addition to a genomic axis label, it can also be useful to include an ideogram representation of a chromosome to give a broader context of the location of genomic data. UCSC Giemsa stain cytoband information for various genomic assemblies is retrieved from AnnotationHub for default assemblies, but users can also provide their own Giemsa stain information if they desire.

Ideograms can be plotted both vertically and horizontally:

library(AnnotationHub)
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
library(GenomeInfoDb)

## Get sizes of chromosomes to scale their sizes
tx_db <- TxDb.Hsapiens.UCSC.hg19.knownGene
chromSizes <- GenomeInfoDb::seqlengths(tx_db)
maxChromSize <- max(chromSizes)

pageCreate(
    width = 8.35, height = 4.25, default.units = "inches",
    showGuides = FALSE, xgrid = 0, ygrid = 0
)
xCoord <- 0.15
for (chr in c(paste0("chr", seq(1, 22)), "chrX", "chrY")) {
    height <- (4 * chromSizes[[chr]]) / maxChromSize
    plotIdeogram(
        chrom = chr, assembly = "hg19",
        orientation = "v",
        x = xCoord, y = 4,
        width = 0.2, height = height,
        just = "bottom"
    )
    plotText(
        label = gsub("chr", "", chr),
        x = xCoord, y = 4.1, fontsize = 10
    )
    xCoord <- xCoord + 0.35
}

pageCreate(
    width = 6.25, height = 0.5, default.units = "inches",
    showGuides = FALSE, xgrid = 0, ygrid = 0
)

plotIdeogram(
    chrom = "chr1", assembly = "hg19",
    orientation = "h",
    x = 0.25, y = unit(0.25, "npc"), width = 5.75, height = 0.3
)

The cytobands can also be hidden if a more minimal ideogram is preferred:

plotIdeogram(
    showBands = FALSE,
    chrom = "chr1", assembly = "hg19",
    orientation = "h",
    x = 0.25, y = unit(0.25, "npc"), width = 5.75, height = 0.3
)

To highlight a specific genomic region on an ideogram, see the article Plot Annotations.

Images and basic shapes

plotgardener also allows users to plot images and basic shapes and elements to further enhance and customize plot layouts. The functions plotCircle(), plotPolygon(), plotRaster(), plotRect(), plotSegments(), and plotText() provide an intuitive way to plot basic grid grobs without requiring any knowledge of grid graphics.

For example, we can include plotgardener’s Gene the Gnome in our figures!:

library(png)
pg_type <- readPNG(system.file("images",
                        "pg-wordmark.png",
                        package = "plotgardener"))

gene_gnome <- readPNG(system.file("images",    
            "pg-gnome-hole-shadow.png",
            package = "plotgardener" ))

pageCreate(
    width = 5, height = 6, default.units = "inches",
    showGuides = FALSE, xgrid = 0, ygrid = 0
)
plotRaster(
    image = pg_type,
    x = 2.5, y = 0.25, width = 4, height = 1.5, just = "top"
)
plotRaster(
    image = gene_gnome,
    x = 2.5, y = 1, width = 3.5, height = 3.5, just = "top"
)

For more detailed usage of basic shape functions, see the function-specific reference examples with ?function() (e.g. ?plotCircle()).

Other grob objects

We saw how to add ggplots and ComplexHeatmaps to plotgardener layouts in the vignette Incorporating ggplots and other grid-based Bioconductor visualizations" with the plotGG() function. Beyond customizing the coordinates and dimensions of ggplots and grid-based Bioconductor visualizations, plotGG() can also be used to incorporate other grob and gtable objects. Thus, plotgardener allows us to easily mix and arrange most kinds of plot objects for ultimate customization.

Session Info

sessionInfo()
#> R version 4.2.0 (2022-04-22)
#> Platform: x86_64-apple-darwin17.0 (64-bit)
#> Running under: macOS Big Sur/Monterey 10.16
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> attached base packages:
#> [1] stats4    grid      stats     graphics  grDevices utils     datasets 
#> [8] methods   base     
#> 
#> other attached packages:
#>  [1] png_0.1-7                              
#>  [2] TxDb.Hsapiens.UCSC.hg19.knownGene_3.2.2
#>  [3] GenomicFeatures_1.48.0                 
#>  [4] AnnotationDbi_1.58.0                   
#>  [5] Biobase_2.56.0                         
#>  [6] GenomicRanges_1.48.0                   
#>  [7] GenomeInfoDb_1.32.0                    
#>  [8] IRanges_2.30.0                         
#>  [9] S4Vectors_0.34.0                       
#> [10] AnnotationHub_3.4.0                    
#> [11] BiocFileCache_2.4.0                    
#> [12] dbplyr_2.1.1                           
#> [13] BiocGenerics_0.42.0                    
#> [14] plotgardenerData_1.1.0                 
#> [15] plotgardener_1.2.0                     
#> 
#> loaded via a namespace (and not attached):
#>   [1] colorspace_2.0-3              rjson_0.2.21                 
#>   [3] ellipsis_0.3.2                showtext_0.9-5               
#>   [5] rprojroot_2.0.3               XVector_0.36.0               
#>   [7] fs_1.5.2                      rstudioapi_0.13              
#>   [9] showtextdb_3.0                bit64_4.0.5                  
#>  [11] interactiveDisplayBase_1.34.0 fansi_1.0.3                  
#>  [13] xml2_1.3.3                    cachem_1.0.6                 
#>  [15] knitr_1.39                    jsonlite_1.8.0               
#>  [17] Rsamtools_2.12.0              shiny_1.7.1                  
#>  [19] BiocManager_1.30.17           compiler_4.2.0               
#>  [21] httr_1.4.2                    assertthat_0.2.1             
#>  [23] Matrix_1.4-1                  fastmap_1.1.0                
#>  [25] cli_3.3.0                     later_1.3.0                  
#>  [27] htmltools_0.5.2               prettyunits_1.1.1            
#>  [29] tools_4.2.0                   gtable_0.3.0                 
#>  [31] glue_1.6.2                    GenomeInfoDbData_1.2.8       
#>  [33] dplyr_1.0.9                   rappdirs_0.3.3               
#>  [35] Rcpp_1.0.8.3                  jquerylib_0.1.4              
#>  [37] pkgdown_2.0.3                 vctrs_0.4.1                  
#>  [39] Biostrings_2.64.0             strawr_0.0.9                 
#>  [41] rtracklayer_1.56.0            xfun_0.30                    
#>  [43] stringr_1.4.0                 plyranges_1.16.0             
#>  [45] mime_0.12                     lifecycle_1.0.1              
#>  [47] restfulr_0.0.13               XML_3.99-0.9                 
#>  [49] zlibbioc_1.42.0               scales_1.2.0                 
#>  [51] ragg_1.2.2                    hms_1.1.1                    
#>  [53] promises_1.2.0.1              MatrixGenerics_1.8.0         
#>  [55] parallel_4.2.0                SummarizedExperiment_1.26.0  
#>  [57] RColorBrewer_1.1-3            yaml_2.3.5                   
#>  [59] curl_4.3.2                    memoise_2.0.1                
#>  [61] ggplot2_3.3.5                 yulab.utils_0.0.4            
#>  [63] sass_0.4.1                    biomaRt_2.52.0               
#>  [65] stringi_1.7.6                 RSQLite_2.2.12               
#>  [67] highr_0.9                     BiocVersion_3.15.2           
#>  [69] BiocIO_1.6.0                  desc_1.4.1                   
#>  [71] filelock_1.0.2                BiocParallel_1.30.0          
#>  [73] rlang_1.0.2                   pkgconfig_2.0.3              
#>  [75] systemfonts_1.0.4             matrixStats_0.62.0           
#>  [77] bitops_1.0-7                  evaluate_0.15                
#>  [79] lattice_0.20-45               purrr_0.3.4                  
#>  [81] GenomicAlignments_1.32.0      bit_4.0.4                    
#>  [83] tidyselect_1.1.2              magrittr_2.0.3               
#>  [85] R6_2.5.1                      generics_0.1.2               
#>  [87] DelayedArray_0.22.0           DBI_1.1.2                    
#>  [89] withr_2.5.0                   pillar_1.7.0                 
#>  [91] KEGGREST_1.36.0               RCurl_1.98-1.6               
#>  [93] tibble_3.1.6                  crayon_1.5.1                 
#>  [95] utf8_1.2.2                    rmarkdown_2.14               
#>  [97] sysfonts_0.8.8                progress_1.2.2               
#>  [99] data.table_1.14.2             blob_1.2.3                   
#> [101] digest_0.6.29                 xtable_1.8-4                 
#> [103] httpuv_1.6.5                  gridGraphics_0.5-1           
#> [105] textshaping_0.3.6             munsell_0.5.0                
#> [107] ggplotify_0.1.0               bslib_0.3.1