x-axis ticks are misaligned in ggbio tracks
1
0
Entering edit mode
cooketho • 0
@cooketho-7308
Last seen 6.9 years ago
United States

I'm trying to make a gene model plot using the ggbio tracks function. When I do autoplot alone, it looks fine, but when I use tracks, the x-axis ticks are misaligned. Please see if you can reproduce the issue using the code below:

library(ggbio)
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene

data(genesymbol, package = "biovizBase")
wh <- genesymbol[c("BRCA1", "NBR1")]
wh <- range(wh, ignore.strand = TRUE)

p <- autoplot(txdb, which=wh)

# Plot 1: http://www.stanford.edu/~cooketho/test1.png

p

# Plot 2: http://www.stanford.edu/~cooketho/test2.png
tracks(p, p)

sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-pc-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=en_US.UTF-8 LC_NAME=C

[9] LC_ADDRESS=C LC_TELEPHONE=C

[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C 

attached base packages:
[1] stats4 parallel stats graphics grDevices utils datasets 
[8] methods base 

other attached packages:
[1] XVector_0.6.0

[2] TxDb.Hsapiens.UCSC.hg19.knownGene_3.0.0
[3] GenomicFeatures_1.18.3

[4] AnnotationDbi_1.28.1

[5] Biobase_2.26.0

[6] GenomicRanges_1.18.4

[7] GenomeInfoDb_1.2.4

[8] IRanges_2.0.1

[9] S4Vectors_0.4.0

[10] ggbio_1.14.0

[11] ggplot2_1.0.0

[12] BiocGenerics_0.12.1 

loaded via a namespace (and not attached):
[1] acepack_1.3-3.3 base64enc_0.1-2 BatchJobs_1.5

[4] BBmisc_1.8 BiocParallel_1.0.1 biomaRt_2.22.0

[7] Biostrings_2.34.1 biovizBase_1.14.1 bitops_1.0-6

[10] brew_1.0-6 BSgenome_1.34.1 checkmate_1.5.1

[13] cluster_1.15.3 codetools_0.2-10 colorspace_1.2-4

[16] DBI_0.3.1 dichromat_2.0-0 digest_0.6.8

[19] fail_1.2 foreach_1.4.2 foreign_0.8-62

[22] Formula_1.2-0 GenomicAlignments_1.2.1 GGally_0.5.0

[25] graph_1.44.1 grid_3.1.2 gridExtra_0.9.1

[28] gtable_0.1.2 Hmisc_3.14-6 iterators_1.0.7

[31] labeling_0.3 lattice_0.20-29 latticeExtra_0.6-26

[34] MASS_7.3-37 munsell_0.4.2 nnet_7.3-8

[37] OrganismDbi_1.8.0 plyr_1.8.1 proto_0.3-10

[40] RBGL_1.42.0 RColorBrewer_1.1-2 Rcpp_0.11.4

[43] RCurl_1.95-4.5 reshape_0.8.5 reshape2_1.4.1

[46] rpart_4.1-8 Rsamtools_1.18.2 RSQLite_1.0.0

[49] rtracklayer_1.26.2 scales_0.2.4 sendmailR_1.2-1

[52] splines_3.1.2 stringr_0.6.2 survival_2.37-7

[55] tools_3.1.2 VariantAnnotation_1.12.9 XML_3.98-1.1

[58] zlibbioc_1.12.0 

 

I also tried the developmental version, and had the same problem (see package info below):

> sessionInfo()
R Under development (unstable) (2015-02-03 r67717)
Platform: x86_64-unknown-linux-gnu (64-bit)
Running under: Ubuntu precise (12.04.4 LTS)

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=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats4    parallel  stats     graphics  grDevices utils     datasets 
[8] methods   base     

other attached packages:
 [1] TxDb.Hsapiens.UCSC.hg19.knownGene_3.0.0
 [2] GenomicFeatures_1.19.18                
 [3] AnnotationDbi_1.29.17                  
 [4] Biobase_2.27.1                         
 [5] GenomicRanges_1.19.35                  
 [6] GenomeInfoDb_1.3.12                    
 [7] BiocInstaller_1.17.5                   
 [8] XVector_0.7.3                          
 [9] IRanges_2.1.36                         
[10] S4Vectors_0.5.17                       
[11] ggbio_1.15.1                           
[12] ggplot2_1.0.0                          
[13] BiocGenerics_0.13.4                    

loaded via a namespace (and not attached):
 [1] Rcpp_0.11.4               biovizBase_1.15.2        
 [3] lattice_0.20-29           Rsamtools_1.19.26        
 [5] Biostrings_2.35.7         digest_0.6.8             
 [7] foreach_1.4.2             plyr_1.8.1               
 [9] BatchJobs_1.5             acepack_1.3-3.3          
[11] RSQLite_1.0.0             zlibbioc_1.13.0          
[13] rpart_4.1-8               checkmate_1.5.1          
[15] labeling_0.3              proto_0.3-10             
[17] splines_3.2.0             BiocParallel_1.1.13      
[19] stringr_0.6.2             foreign_0.8-62           
[21] RCurl_1.95-4.5            biomaRt_2.23.5           
[23] munsell_0.4.2             sendmailR_1.2-1          
[25] rtracklayer_1.27.7        base64enc_0.1-2          
[27] BBmisc_1.9                nnet_7.3-8               
[29] fail_1.2                  gridExtra_0.9.1          
[31] Hmisc_3.14-6              codetools_0.2-10         
[33] XML_3.98-1.1              reshape_0.8.5            
[35] GenomicAlignments_1.3.27  MASS_7.3-38              
[37] bitops_1.0-6              grid_3.2.0               
[39] RBGL_1.43.0               GGally_0.5.0             
[41] gtable_0.1.2              DBI_0.3.1                
[43] scales_0.2.4              graph_1.45.1             
[45] reshape2_1.4.1            latticeExtra_0.6-26      
[47] brew_1.0-6                Formula_1.2-0            
[49] RColorBrewer_1.1-2        iterators_1.0.7          
[51] tools_3.2.0               dichromat_2.0-0          
[53] BSgenome_1.35.16          OrganismDbi_1.9.3        
[55] survival_2.37-7           colorspace_1.2-4         
[57] cluster_2.0.1             VariantAnnotation_1.13.28

ggbio bugs tracks autoplot • 1.1k views
ADD COMMENT
0
Entering edit mode

I do see the issue you are reporting but it took a bit of gawking to appreciate it.

It seems that the data space was rescaled to cope with the additional vertical content but

the bounding geometry was not updated.  Please contact the maintainer, your example is very clear.

ADD REPLY
0
Entering edit mode
cooketho • 0
@cooketho-7308
Last seen 6.9 years ago
United States

Thanks for the response Vincent! I've contacted the maintainer.

In the meantime, I found a workaround (below) using grid that approximates the output of tracks, but has correctly aligned x-axis ticks.

http://stanford.edu/~cooketho/test1.pdf

http://stanford.edu/~cooketho/test2.pdf

http://stanford.edu/~cooketho/test3.pdf

library(grid)
library(ggbio)
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene

data(genesymbol, package = "biovizBase")
wh <- genesymbol[c("BRCA1", "NBR1")]
wh <- range(wh, ignore.strand = TRUE)

# Make a gene model, as in the vignette.
p <- autoplot(txdb, which=wh)
# Make a pdf of the plot.
pdf('test1.pdf')
p
dev.off()
# OK. So far so good!

# Stack two of the same plot on top of each other with tracks.
q <- tracks(p, p)
pdf('test2.pdf')
q
dev.off()

# Oops! X-axis ticks are misaligned.

# Try the same thing using grid:
# Get the ggplot2 object from the ggbio object.
p2 <- p@ggplot
# Make an upper plot without x-axis ticks.
p3 <- p2 + theme(axis.text.x = element_blank(), axis.ticks.x = element_blank())
# Convert to grobs and align them with gtable.
p4 <- gtable:::rbind_gtable(ggplotGrob(p3), ggplotGrob(p2), "first")
# Draw the grobs with grid.
pdf('test3.pdf')
grid.draw(p4)
dev.off()
# Looks better!

ADD COMMENT

Login before adding your answer.

Traffic: 361 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6