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:
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.
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()
).
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.
sessionInfo()
#> R version 4.3.2 (2023-10-31)
#> Platform: x86_64-apple-darwin20 (64-bit)
#> Running under: macOS Sonoma 14.2.1
#>
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
#>
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#>
#> time zone: America/New_York
#> tzcode source: internal
#>
#> attached base packages:
#> [1] stats4 grid stats graphics grDevices utils datasets
#> [8] methods base
#>
#> other attached packages:
#> [1] png_0.1-8
#> [2] TxDb.Hsapiens.UCSC.hg19.knownGene_3.2.2
#> [3] GenomicFeatures_1.54.4
#> [4] AnnotationDbi_1.64.1
#> [5] Biobase_2.62.0
#> [6] GenomicRanges_1.54.1
#> [7] GenomeInfoDb_1.38.8
#> [8] IRanges_2.36.0
#> [9] S4Vectors_0.40.2
#> [10] AnnotationHub_3.10.0
#> [11] BiocFileCache_2.10.1
#> [12] dbplyr_2.5.0
#> [13] BiocGenerics_0.48.1
#> [14] plotgardenerData_1.8.0
#> [15] plotgardener_1.8.2
#>
#> loaded via a namespace (and not attached):
#> [1] DBI_1.2.2 bitops_1.0-7
#> [3] biomaRt_2.58.2 rlang_1.1.3
#> [5] magrittr_2.0.3 matrixStats_1.2.0
#> [7] compiler_4.3.2 RSQLite_2.3.5
#> [9] systemfonts_1.0.6 vctrs_0.6.5
#> [11] sysfonts_0.8.9 stringr_1.5.1
#> [13] pkgconfig_2.0.3 crayon_1.5.2
#> [15] fastmap_1.1.1 XVector_0.42.0
#> [17] utf8_1.2.4 promises_1.2.1
#> [19] Rsamtools_2.18.0 rmarkdown_2.26
#> [21] strawr_0.0.91 ragg_1.3.0
#> [23] purrr_1.0.2 bit_4.0.5
#> [25] xfun_0.43 showtext_0.9-7
#> [27] zlibbioc_1.48.2 cachem_1.0.8
#> [29] jsonlite_1.8.8 progress_1.2.3
#> [31] blob_1.2.4 highr_0.10
#> [33] later_1.3.2 DelayedArray_0.28.0
#> [35] BiocParallel_1.36.0 interactiveDisplayBase_1.40.0
#> [37] prettyunits_1.2.0 parallel_4.3.2
#> [39] R6_2.5.1 plyranges_1.22.0
#> [41] stringi_1.8.3 bslib_0.7.0
#> [43] RColorBrewer_1.1-3 rtracklayer_1.62.0
#> [45] jquerylib_0.1.4 Rcpp_1.0.12
#> [47] SummarizedExperiment_1.32.0 knitr_1.45
#> [49] httpuv_1.6.15 Matrix_1.6-5
#> [51] tidyselect_1.2.1 rstudioapi_0.16.0
#> [53] abind_1.4-5 yaml_2.3.8
#> [55] codetools_0.2-19 curl_5.2.1
#> [57] lattice_0.22-6 tibble_3.2.1
#> [59] KEGGREST_1.42.0 shiny_1.8.1
#> [61] withr_3.0.0 evaluate_0.23
#> [63] gridGraphics_0.5-1 desc_1.4.3
#> [65] xml2_1.3.6 Biostrings_2.70.3
#> [67] pillar_1.9.0 BiocManager_1.30.22
#> [69] filelock_1.0.3 MatrixGenerics_1.14.0
#> [71] generics_0.1.3 RCurl_1.98-1.14
#> [73] hms_1.1.3 BiocVersion_3.18.1
#> [75] ggplot2_3.5.0 munsell_0.5.0
#> [77] scales_1.3.0 xtable_1.8-4
#> [79] glue_1.7.0 tools_4.3.2
#> [81] BiocIO_1.12.0 data.table_1.15.2
#> [83] GenomicAlignments_1.38.2 fs_1.6.3
#> [85] XML_3.99-0.16.1 colorspace_2.1-0
#> [87] GenomeInfoDbData_1.2.11 showtextdb_3.0
#> [89] restfulr_0.0.15 cli_3.6.2
#> [91] rappdirs_0.3.3 textshaping_0.3.7
#> [93] fansi_1.0.6 S4Arrays_1.2.1
#> [95] dplyr_1.1.4 gtable_0.3.4
#> [97] yulab.utils_0.1.4 sass_0.4.9
#> [99] digest_0.6.35 SparseArray_1.2.4
#> [101] ggplotify_0.1.2 rjson_0.2.21
#> [103] memoise_2.0.1 htmltools_0.5.8
#> [105] pkgdown_2.0.7 lifecycle_1.0.4
#> [107] httr_1.4.7 mime_0.12
#> [109] bit64_4.0.5