plotgardener plots are extremely customizable in appearance. In this article we will outline some of the major aesthetic customizations, including general features and specific plot type customizations.

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

gpar and common plot customizations

The most common types of customizations are inherited from grid gpar options. If a function accepts ..., this usually refers to gpar options that are not explicity listed as parameters in the function documentation. General valid parameters include:

alpha Alpha channel for transparency (number between 0 and 1).
fill Fill color.
linecolor Line color.
lty Line type. (0=blank, 1=solid, 2=dashed, 3=dotted, 4=dotdash, 5=longdash, 6=twodash).
lwd Line width.
lineend Line end style (round, butt, square).
linejoin Line join style (round, mitre, bevel).
linemitre Line mitre limit (number greater than 1).
fontsize The size of text, in points.
fontcolor Text color.
fontface The font face (plain, bold, italic, bold.italic, oblique).
fontfamily The font family.
cex Scaling multiplier applied to symbols.
pch Plotting character, or symbol (integer codes range from 0 to 25).

Additional fonts for the fontfamily argument can be imported with the packages extrafont and showtext. This makes it possible to incorporate special fonts like Times New Roman, Arial, etc. into plotgardener figures.

Backgrounds and baselines

By default, plotgardener plots have transparent backgrounds when placed on a page. In many functions, this background color can be changed with the parameter bg.

plotGenes(
    chrom = "chr8", chromstart = 1000000, chromend = 2000000,
    assembly = "hg19",
    bg = "#f6f6f6",
    x = 0.5, y = 0.5, width = 2, height = 1, just = c("left", "top"),
    default.units = "inches"
)

This makes it easy to clearly see the precise dimensional boundaries of plotgardener plots.

Some plots also benefit from baselines to quickly show where y = 0. This can aid in data interpretation and guide plot annotation placement. Baselines can be plotted in selective plots with baseline = TRUE.

plotRanges(
    data = IMR90_ChIP_CTCF_reads,
    chrom = "chr21", chromstart = 29073000, chromend = 29074000,
    assembly = "hg19",
    fill = c("#7ecdbb", "#37a7db"),
    baseline = TRUE, baseline.color = "black",
    x = 0.5, y = 0.25, width = 6.5, height = 4.25,
    just = c("left", "top"), default.units = "inches"
)

Gene and transcript plot aesthetics

plotgardener provides many useful features specific for enhancing gene and transcript visualizations:

Labels

Since plotgardener utilizes TxDb objects, orgDb objects, and internal citation information, plotgardener has access to numerous gene and transcript identifiers and can customize annotation labels in a variety of ways.

By default, plotgardener will rank gene labels according to citation number to prevent label overcrowding. However, we can provide our own list of prioritized genes to label in a plot. For example, if we plot the hg19 genes in the region chr2:1000000-20000000, our plot will show these labels:

pageCreate(
    width = 5, height = 1.25,
    showGuides = FALSE, xgrid = 0, ygrid = 0
)
genePlot <- plotGenes(
    chrom = "chr2", chromstart = 1000000, chromend = 20000000,
    assembly = "hg19",
    x = 0.25, y = 0.25, width = 4.75, height = 1
)

Looking in the genes object, we can see that there were numerous genes that were not labeled.

genePlot$genes
#>  [1] "MIR3125"      "RNASEH1-DT"   "LOC100506274" "MIR4757"      "LINC00570"   
#>  [6] "C2orf50"      "SLC66A3"      "SILC1"        "LRATD1"       "DDX1"        
#> [11] "LPIN1"        "ATP6V1C2"     "IAH1"         "TRIB2"        "GRHL1"       
#> [16] "HPCAL1"       "ID2"          "MSGN1"        "GEN1"         NA            
#> [21] "KCNF1"        "KCNS3"        "LOC400940"    "MYCN"         "TRAPPC12"    
#> [26] "CPSF3"        "SNTG2"        "ALLC"         "RPS7"         "RRM2"        
#> [31] "SOX11"        "TPO"          "MYT1L-AS1"    "VSNL1"        "COLEC11"     
#> [36] "KLF11"        "ASAP2"        "TAF1B"        "RSAD2"        "GREB1"       
#> [41] "RNF144A"      "SNORA80B"     "MIR4261"      "MIR4262"      "LINC01304"   
#> [46] "LOC100506474" "NT5C1B-RDH14" "MIR4429"      "PDIA6"        "MYCNOS"      
#> [51] "YWHAQ"        "CMPK2"        "MBOAT2"       "OSR1"         "E2F6"        
#> [56] "CYS1"         "MYT1L"        "NTSR2"        "RNASEH1"      "FLJ33534"    
#> [61] "LINC00298"    "LINC00299"    "GRASLND"      "LINC00487"    "ODC1"        
#> [66] "NBAS"         "ADI1"         "KIDINS220"    "RDH14"        "ADAM17"      
#> [71] "EIPR1"        "LINC01249"    "RAD51AP2"     "PXDN"         "SMC6"        
#> [76] "NOL10"        "CYRIA"        "ITGB1BP1"     "NT5C1B"       "ROCK2"

If we were particularly interested in MIR3125, we could include this in the geneOrder parameter to prioritize its labeling:

pageCreate(
    width = 5, height = 1.25,
    showGuides = FALSE, xgrid = 0, ygrid = 0
)
genePlot <- plotGenes(
    chrom = "chr2", chromstart = 1000000, chromend = 20000000,
    assembly = "hg19",
    geneOrder = c("MIR3125"),
    x = 0.25, y = 0.25, width = 4.75, height = 1
)

Label IDs used in transcript plots can be customized through assembly() objects, and transcript label formatting can be changed through the labels parameter. For example, if we wish to display both transcript names and their associated gene names, we can set labels = "both":

pageCreate(
    width = 6, height = 5,
    showGuides = FALSE, xgrid = 0, ygrid = 0
)
transcriptPlot <- plotTranscripts(
    chrom = "chr2", chromstart = 1000000, chromend = 20000000,
    assembly = "hg19",
    labels = "both",
    x = 0.25, y = 0.25, width = 5.5, height = 4.5
)

Highlighting genes by color

In addition to changing fill and fontcolor to change the colors of all genes in a plot, specific gene structures and their labels can be highlighted in a different color with geneHighlights. If we revisit the genes plot above, we can highlight RRM2 by creating a data.frame with “RRM2” in the first column and its highlight color in the second column:

geneHighlights <- data.frame("geneName" = "RRM2", "color" = "steel blue")

We can then pass this into our plotGenes() call:

pageCreate(
    width = 5, height = 1.25,
    showGuides = FALSE, xgrid = 0, ygrid = 0
)
genePlot <- plotGenes(
    chrom = "chr2", chromstart = 1000000, chromend = 20000000,
    assembly = "hg19",
    geneHighlights = geneHighlights, geneBackground = "grey",
    x = 0.25, y = 0.25, width = 4.75, height = 1
)

Since geneHighlights is a data.frame, we can highlight multiple genes in different colors at once. For example, let’s now highlight RRM2 in “steel blue” and PXDN in “red”:

geneHighlights <- data.frame(
    "geneName" = c("RRM2", "PXDN"),
    "color" = c("steel blue", "red")
)

pageCreate(
    width = 5, height = 1.25,
    showGuides = FALSE, xgrid = 0, ygrid = 0
)
genePlot <- plotGenes(
    chrom = "chr2", chromstart = 1000000, chromend = 20000000,
    assembly = "hg19",
    geneHighlights = geneHighlights, geneBackground = "grey",
    x = 0.25, y = 0.25, width = 4.75, height = 1
)

Highlighting transcripts by color

Similar to highlighting specific genes by colors, specific transcripts can also be highlighted with transcriptHighlights. We can do this by either specifying transcripts by name or transcripts by their genes. Let’s plot the transcripts of the gene track above and label the transcripts of LPIN1 and CMPK2:

transcriptHighlights <- data.frame(
    "gene" = c("LPIN1", "CMPK2"),
    "color" = c("steel blue", "red")
)

pageCreate(
    width = 6, height = 7,
    showGuides = FALSE
)
transcriptPlot <- plotTranscripts(
    chrom = "chr2", chromstart = 1000000, chromend = 20000000,
    assembly = "hg19",
    transcriptHighlights = transcriptHighlights,
    colorbyStrand = FALSE, fill = "grey",
    x = 0.25, y = 0.25, width = 5.5, height = 4.5
)

We can now see all transcripts of CMPK2 are colored in red and all transcripts of LPIN1 are colored in steel blue. If we knew the precise names of these transcripts, we could also specify them for transcript highlighting with the following data.frame:

transcriptHighlights <- data.frame(
    "transcript" = c("uc010yjo.2", "uc002rbt.4", "uc010yjn.3", "uc002rbs.4",
                    "uc010yjm.3","uc010exi.1", "uc031rno.1", "uc010ewv.4",
                    "uc002qyo.4", "uc010yis.2", "uc002qyn.2"),
    "color" = c("steel blue", "steel blue", "steel blue", "steel blue",
                "steel blue", "steel blue", "red", "red", "red", "red", "red")
)

Customizing transcripts by strand

To distinguish which strand a transcript belongs to, plotTranscripts() colors transcripts by strand with the parameter colorbyStrand. The first value in fill colors positive strand transcripts and the second fill value colors negative strand transcripts. To further organize transcripts by strand, we can use strandSplit to separate transcript elements into groups of positive and negative strands:

pageCreate(
    width = 6, height = 5,
    showGuides = FALSE, xgrid = 0, ygrid = 0
)
transcriptPlot <- plotTranscripts(
    chrom = "chr2", chromstart = 1000000, chromend = 20000000,
    assembly = "hg19",
    strandSplit = TRUE,
    x = 0.25, y = 0.25, width = 5.5, height = 4.5
)

Now all our positive strand transcripts are grouped together above the group of negative strand transcripts.

Hi-C plot customizations

plotgardener includes many types of customizations for Hi-C plots. plotgardener provides 3 different Hi-C plotting functions based on the desired plot shape:

  • plotHicSquare(): Plots a square, symmetrical Hi-C plot with genomic coordinates along both the x- and y-axes.

  • plotHicTriangle(): Plots a triangular Hi-C plot where the genome region falls along the base of the triangle.

  • plotHicRectangle(): Plots a triangular Hi-C plot with additional data filling the surrounding regions to form a rectangle.

All Hi-C plot types can use different color palettes, and colors can be linearly or log-scaled with the colorTrans parameter.

hicSquare plots can be further customized to include two datasets in one plot. Instead of plotting both symmetrical halves of the plot, we can set one dataset as half = "top" and the other dataset as half = "bottom":

data("GM12878_HiC_10kb")
data("IMR90_HiC_10kb")

pageCreate(
    width = 3.25, height = 3.25, default.units = "inches",
    showGuides = FALSE, xgrid = 0, ygrid = 0
)
params <- pgParams(
    chrom = "chr21", chromstart = 28000000, chromend = 30300000,
    assembly = "hg19", resolution = 10000,
    x = 0.25, width = 2.75, just = c("left", "top"), default.units = "inches"
)


hicPlot_top <- plotHicSquare(
    data = GM12878_HiC_10kb, params = params,
    zrange = c(0, 200),
    half = "top",
    y = 0.25, height = 2.75
)
hicPlot_bottom <- plotHicSquare(
    data = IMR90_HiC_10kb, params = params,
    zrange = c(0, 70),
    half = "bottom",
    y = 0.25, height = 2.75
)

Session Info

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            bslib_0.7.0                
#>  [39] stringi_1.8.3               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