vignettes/introduction_to_plotgardener.Rmd
introduction_to_plotgardener.Rmd
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
.
plotgardener
plotting functions contain 4 types of
arguments:
Data reading argument (data
)
Genomic locus arguments (chrom
,
chromstart
, chromend
,
assembly
)
Placement arguments (x
, y
,
width
, height
, just
,
default.units
, …) that define where each plot resides on a
page
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.
## Load plotgardener
library(plotgardener)
## Load example Hi-C data
library(plotgardenerData)
data("IMR90_HiC_10kb")
## Quick plot Hi-C data
plotHicSquare(
data = IMR90_HiC_10kb,
chrom = "chr21", chromstart = 28000000, chromend = 30300000,
assembly = "hg19"
)
## Load plotgardener
library(plotgardener)
## Load example signal data
library(plotgardenerData)
data("IMR90_ChIP_H3K27ac_signal")
## Quick plot signal data
plotSignal(
data = IMR90_ChIP_H3K27ac_signal,
chrom = "chr21", chromstart = 28000000, chromend = 30300000,
assembly = "hg19"
)
## Load plotgardener
library(plotgardener)
## Load hg19 genomic annotation packages
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
library(org.Hs.eg.db)
## Quick plot genes
plotGenes(
assembly = "hg19",
chrom = "chr21", chromstart = 28000000, chromend = 30300000
)
## Load plotgardener
library(plotgardener)
## Load hg19 genomic annotation packages
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
## Load example GWAS data
library(plotgardenerData)
data("hg19_insulin_GWAS")
## Quick plot GWAS data
plotManhattan(
data = hg19_insulin_GWAS,
assembly = "hg19",
fill = c("steel blue", "grey"),
ymax = 1.1, cex = 0.20
)
plotgardener
page
To build complex, multi-panel plotgardener
figures with
annotations, we must:
plotgardener
coordinate page with
pageCreate()
.
pageCreate(width = 3.25, height = 3.25, default.units = "inches")
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"
)
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.
When a plotgardener
plot is ready to be saved and
exported, we can first remove all page guides that were made with
pageCreate()
:
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()
Please note that due to the implementation of
grid
removal functions, using
pageGuideHide
within a pdf
call will result in
the rendering of a separate, new page with the plot
guides removed. To avoid this artifact, hide guides in
the pageCreate
function call with
showGuides = FALSE
.
For more detailed usage and examples, please refer to the other available vignettes.
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!
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] org.Hs.eg.db_3.18.0
## [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] BiocGenerics_0.48.1
## [11] plotgardenerData_1.8.0
## [12] 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] png_0.1-8 systemfonts_1.0.6
## [11] vctrs_0.6.5 stringr_1.5.1
## [13] pkgconfig_2.0.3 crayon_1.5.2
## [15] fastmap_1.1.1 dbplyr_2.5.0
## [17] XVector_0.42.0 utf8_1.2.4
## [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 zlibbioc_1.48.2
## [27] cachem_1.0.8 jsonlite_1.8.8
## [29] progress_1.2.3 blob_1.2.4
## [31] highr_0.10 DelayedArray_0.28.0
## [33] BiocParallel_1.36.0 parallel_4.3.2
## [35] prettyunits_1.2.0 R6_2.5.1
## [37] plyranges_1.22.0 stringi_1.8.3
## [39] bslib_0.7.0 RColorBrewer_1.1-3
## [41] rtracklayer_1.62.0 jquerylib_0.1.4
## [43] Rcpp_1.0.12 SummarizedExperiment_1.32.0
## [45] knitr_1.45 Matrix_1.6-5
## [47] tidyselect_1.2.1 rstudioapi_0.16.0
## [49] abind_1.4-5 yaml_2.3.8
## [51] codetools_0.2-19 curl_5.2.1
## [53] lattice_0.22-6 tibble_3.2.1
## [55] withr_3.0.0 KEGGREST_1.42.0
## [57] evaluate_0.23 gridGraphics_0.5-1
## [59] desc_1.4.3 BiocFileCache_2.10.1
## [61] xml2_1.3.6 Biostrings_2.70.3
## [63] filelock_1.0.3 pillar_1.9.0
## [65] MatrixGenerics_1.14.0 generics_0.1.3
## [67] RCurl_1.98-1.14 hms_1.1.3
## [69] ggplot2_3.5.0 munsell_0.5.0
## [71] scales_1.3.0 glue_1.7.0
## [73] tools_4.3.2 BiocIO_1.12.0
## [75] data.table_1.15.2 GenomicAlignments_1.38.2
## [77] fs_1.6.3 XML_3.99-0.16.1
## [79] colorspace_2.1-0 GenomeInfoDbData_1.2.11
## [81] restfulr_0.0.15 cli_3.6.2
## [83] rappdirs_0.3.3 textshaping_0.3.7
## [85] fansi_1.0.6 S4Arrays_1.2.1
## [87] dplyr_1.1.4 gtable_0.3.4
## [89] yulab.utils_0.1.4 sass_0.4.9
## [91] digest_0.6.35 SparseArray_1.2.4
## [93] ggplotify_0.1.2 rjson_0.2.21
## [95] memoise_2.0.1 htmltools_0.5.8
## [97] pkgdown_2.0.7 lifecycle_1.0.4
## [99] httr_1.4.7 bit64_4.0.5