layout_karyogram {ggbio} | R Documentation |
Create a karyogram layout.
## S4 method for signature 'GRanges' layout_karyogram(data, ..., xlab, ylab, main, facets = seqnames ~ ., cytoband = FALSE, geom = NULL, stat = NULL, ylim = NULL, rect.height = 10)
data |
a |
... |
Extra parameters such as aes() or arbitrary |
xlab |
character vector or expression for x axis label. |
ylab |
character vector or expression for y axis label. |
main |
character vector or expression for plot title. |
facets |
faceting formula to use. |
cytoband |
logical value indicate to show the cytobands or not. |
geom |
The geometric object to use display the data. |
stat |
character vector specifying statistics to use. |
ylim |
limits for y axis, usually the chromosome spaces y limits are from 0 to rect.height, which 10, so if you wan to stack some data on top of it, you can set limits to like c(10, 20). |
rect.height |
numreic value indicate half of the rectangle ploting region, used for alignment of multiple layers. |
A 'Layer'.
Tengfei Yin
### R code from vignette source 'karyogram.Rnw'
###################################################
### code chunk number 1: loading
###################################################
library(ggbio)
data(hg19IdeogramCyto, package = "biovizBase")
head(hg19IdeogramCyto)
## GRanges with 6 ranges and 2 metadata columns:
## seqnames ranges strand | name gieStain
## <Rle> <IRanges> <Rle> | <factor> <factor>
## [1] chr1 [ 0, 2300000] * | p36.33 gneg
## [2] chr1 [ 2300000, 5400000] * | p36.32 gpos25
## [3] chr1 [ 5400000, 7200000] * | p36.31 gneg
## [4] chr1 [ 7200000, 9200000] * | p36.23 gpos25
## [5] chr1 [ 9200000, 12700000] * | p36.22 gneg
## [6] chr1 [12700000, 16200000] * | p36.21 gpos50
## ---
## seqlengths:
## chr1 chr10 chr11 chr12 chr13 chr14 ... chr7 chr8 chr9 chrX chrY
## NA NA NA NA NA NA ... NA NA NA NA NA
## default pre-set color stored in
getOption("biovizBase")$cytobandColor
## gneg gpos25 gpos50 gpos75 gpos100 gvar stalk
## "grey100" "grey90" "grey70" "grey40" "grey0" "grey100" "brown3"
## acen
## "brown4"
###################################################
### code chunk number 2: default
###################################################
autoplot(hg19IdeogramCyto, layout = "karyogram", cytoband = TRUE)
###################################################
### code chunk number 3: change-order
###################################################
library(GenomicRanges)
hg19 <- keepSeqlevels(hg19IdeogramCyto, paste0("chr", c(1:22, "X", "Y")))
head(hg19)
## GRanges with 6 ranges and 2 metadata columns:
## seqnames ranges strand | name gieStain
## <Rle> <IRanges> <Rle> | <factor> <factor>
## [1] chr1 [ 0, 2300000] * | p36.33 gneg
## [2] chr1 [ 2300000, 5400000] * | p36.32 gpos25
## [3] chr1 [ 5400000, 7200000] * | p36.31 gneg
## [4] chr1 [ 7200000, 9200000] * | p36.23 gpos25
## [5] chr1 [ 9200000, 12700000] * | p36.22 gneg
## [6] chr1 [12700000, 16200000] * | p36.21 gpos50
## ---
## seqlengths:
## chr1 chr2 chr3 chr4 chr5 chr6 ... chr20 chr21 chr22 chrX chrY
## NA NA NA NA NA NA ... NA NA NA NA NA
autoplot(hg19, layout = "karyogram", cytoband = TRUE)
###################################################
### code chunk number 4: cyto-normal
###################################################
library(GenomicRanges)
## it's a 'ideogram'
biovizBase::isIdeogram(hg19)
## [1] TRUE
## set to FALSE
autoplot(hg19, layout = "karyogram", cytoband = FALSE, aes(fill = gieStain)) +
scale_fill_giemsa()
## Warning: geom(ideogram) need valid seqlengths information for accurate
## mapping, now use reduced information as ideogram...
## Warning: geom(ideogram) need valid seqlengths information for accurate
## mapping, now use reduced information as ideogram...
## Scale for 'x' is already present. Adding another scale for 'x', which will
## replace the existing scale.
###################################################
### code chunk number 5: load-RNAediting
###################################################
data(darned_hg19_subset500, package = "biovizBase")
dn <- darned_hg19_subset500
head(dn)
## GRanges with 6 ranges and 10 metadata columns:
## seqnames ranges strand | inchr inrna
## <Rle> <IRanges> <Rle> | <character> <character>
## [1] chr5 [ 86618225, 86618225] - | A I
## [2] chr7 [ 99792382, 99792382] - | A I
## [3] chr12 [110929076, 110929076] - | A I
## [4] chr20 [ 25818128, 25818128] - | A I
## [5] chr3 [132397992, 132397992] + | A I
## [6] chr19 [ 59078471, 59078471] - | A I
## snp gene seqReg exReg source
## <character> <character> <character> <character> <character>
## [1] <NA> <NA> O <NA> amygdala
## [2] <NA> <NA> O <NA> <NA>
## [3] <NA> <NA> O <NA> salivary gland
## [4] <NA> <NA> O <NA> brain, hippocampus
## [5] <NA> <NA> O <NA> small intestine
## [6] <NA> MZF1 I <NA> <NA>
## ests esta author
## <integer> <integer> <character>
## [1] 0 0 15342557
## [2] 0 0 15342557
## [3] 0 0 15342557
## [4] 0 0 15342557
## [5] 0 0 15342557
## [6] 0 0 15258596
## ---
## seqlengths:
## chr1 chr10 chr11 chr12 chr13 chr14 ... chr6 chr7 chr8 chr9 chrX
## NA NA NA NA NA NA ... NA NA NA NA NA
## add seqlengths
## we have seqlegnths information in another data set
data(hg19Ideogram, package = "biovizBase")
seqlengths(dn) <- seqlengths(hg19Ideogram)[names(seqlengths(dn))]
## now we have seqlengths
head(dn)
## GRanges with 6 ranges and 10 metadata columns:
## seqnames ranges strand | inchr inrna
## <Rle> <IRanges> <Rle> | <character> <character>
## [1] chr5 [ 86618225, 86618225] - | A I
## [2] chr7 [ 99792382, 99792382] - | A I
## [3] chr12 [110929076, 110929076] - | A I
## [4] chr20 [ 25818128, 25818128] - | A I
## [5] chr3 [132397992, 132397992] + | A I
## [6] chr19 [ 59078471, 59078471] - | A I
## snp gene seqReg exReg source
## <character> <character> <character> <character> <character>
## [1] <NA> <NA> O <NA> amygdala
## [2] <NA> <NA> O <NA> <NA>
## [3] <NA> <NA> O <NA> salivary gland
## [4] <NA> <NA> O <NA> brain, hippocampus
## [5] <NA> <NA> O <NA> small intestine
## [6] <NA> MZF1 I <NA> <NA>
## ests esta author
## <integer> <integer> <character>
## [1] 0 0 15342557
## [2] 0 0 15342557
## [3] 0 0 15342557
## [4] 0 0 15342557
## [5] 0 0 15342557
## [6] 0 0 15258596
## ---
## seqlengths:
## chr1 chr10 chr11 chr12 ... chr8 chr9 chrX
## 249250621 135534747 135006516 133851895 ... 146364022 141213431 155270560
## then we change order
dn <- keepSeqlevels(dn, paste0("chr", c(1:22, "X")))
autoplot(dn, layout = "karyogram")
## Scale for 'x' is already present. Adding another scale for 'x', which will
## replace the existing scale.
## this equivalent to
## autoplot(seqinfo(dn))
###################################################
### code chunk number 6: load-RNAediting-color
###################################################
## since default is geom rectangle, even though it's looks like segment
## we still use both fill/color to map colors
autoplot(dn, layout = "karyogram", aes(color = exReg, fill = exReg))
## Scale for 'x' is already present. Adding another scale for 'x', which will
## replace the existing scale.
###################################################
### code chunk number 7: load-RNAediting-color-NA
###################################################
## since default is geom rectangle, even though it's looks like segment
## we still use both fill/color to map colors
autoplot(dn, layout = "karyogram", aes(color = exReg, fill = exReg)) +
scale_color_discrete(na.value = "brown")
## Scale for 'x' is already present. Adding another scale for 'x', which will
## replace the existing scale.
###################################################
### code chunk number 8: load-RNAediting-color-fake
###################################################
dn2 <- dn
seqlengths(dn2) <- rep(max(seqlengths(dn2)), length(seqlengths(dn2)) )
autoplot(dn2, layout = "karyogram", aes(color = exReg, fill = exReg))
## Scale for 'x' is already present. Adding another scale for 'x', which will
## replace the existing scale.
###################################################
### code chunk number 9: plotKaryogram (eval = FALSE)
###################################################
## plotKaryogram(dn)
## plotKaryogram(dn, aes(color = exReg, fill = exReg))
###################################################
### code chunk number 10: low-default
###################################################
## plot ideogram
p <- ggplot(hg19) + layout_karyogram(cytoband = TRUE)
p
## eqevelant autoplot(hg19, layout = "karyogram", cytoband = TRUE)
###################################################
### code chunk number 11: low-default-addon
###################################################
p <- p + layout_karyogram(dn, geom = "rect", ylim = c(11, 21), color = "red")
## Scale for 'x' is already present. Adding another scale for 'x', which will
## replace the existing scale.
## commented line below won't work
## the cytoband fill color has been used already.
## p <- p + layout_karyogram(dn, aes(fill = exReg, color = exReg), geom = "rect")
p
###################################################
### code chunk number 12: edit-space
###################################################
## plot chromosome space
p <- autoplot(seqinfo(dn))
## make sure you pass rect as geom
## otherwise you just get background
p <- p + layout_karyogram(dn, aes(fill = exReg, color = exReg), geom = "rect")
## Scale for 'x' is already present. Adding another scale for 'x', which will
## replace the existing scale.
values(dn)$pvalue <- rnorm(length(dn))
p + layout_karyogram(dn, aes(x = start, y = pvalue), ylim = c(10, 30), geom = "line", color = "red")
## Scale for 'x' is already present. Adding another scale for 'x', which will
## replace the existing scale.
p
###################################################
### code chunk number 13: sessionInfo
###################################################
sessionInfo()
## R Under development (unstable) (2012-07-17 r59871)
## Platform: x86_64-unknown-linux-gnu (64-bit)
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=C LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## attached base packages:
## [1] grid methods stats graphics grDevices utils datasets
## [8] base
##
## other attached packages:
## [1] BSgenome.Hsapiens.UCSC.hg19_1.3.19
## [2] BSgenome_1.25.9
## [3] VariantAnnotation_1.3.32
## [4] genefilter_1.39.0
## [5] vsn_3.25.0
## [6] rtracklayer_1.17.21
## [7] Rsamtools_1.9.31
## [8] Biostrings_2.25.12
## [9] TxDb.Hsapiens.UCSC.hg19.knownGene_2.8.0
## [10] GenomicFeatures_1.9.44
## [11] AnnotationDbi_1.19.46
## [12] Biobase_2.17.8
## [13] GenomicRanges_1.9.66
## [14] IRanges_1.15.48
## [15] BiocGenerics_0.3.2
## [16] ggbio_1.5.20
## [17] ggplot2_0.9.2.1
## [18] knitr_0.8
##
## loaded via a namespace (and not attached):
## [1] affy_1.35.1 affyio_1.25.0 annotate_1.35.5
## [4] BiocInstaller_1.5.12 biomaRt_2.13.2 biovizBase_1.5.9
## [7] bitops_1.0-4.1 cluster_1.14.2 colorspace_1.1-1
## [10] DBI_0.2-5 dichromat_1.2-4 digest_0.5.1
## [13] evaluate_0.4.2 formatR_0.6 gridExtra_0.9.1
## [16] gtable_0.1.1 Hmisc_3.9-3 labeling_0.1
## [19] lattice_0.20-6 limma_3.13.24 markdown_0.5.2
## [22] MASS_7.3-19 memoise_0.1 munsell_0.4
## [25] parallel_2.16.0 plyr_1.7.1 preprocessCore_1.19.0
## [28] proto_0.3-9.2 RColorBrewer_1.0-5 RCurl_1.95-0
## [31] reshape2_1.2.1 RSQLite_0.11.2 scales_0.2.2
## [34] splines_2.16.0 stats4_2.16.0 stringr_0.6.1
## [37] survival_2.36-14 tools_2.16.0 XML_3.95-0
## [40] xtable_1.7-0 zlibbioc_1.3.0