hi all,
I'm exploring ggplot and ggbio - looks like it'll be really useful. But I'm having trouble getting my plots to align on the x axis if one of them has a legend. Is there a way to do make the plots align? or did I accidentally find a bug?
My real example uses the ggbio::plotGrandLinear to make three plots and then uses ggbio::tracks to display them together. But here's a simpler toy example using regular ggplots and ggbio::tracks (based on the first ?tracks example). If you look at this plot, the middle panel that has the legend is not aligned with the others (it's squashed a bit on the x axis). The plot: https://ibb.co/P1ZYn1L
I've had good luck for other multi-panel plots using ggarrange, but that doesn't seem to accept GGbio objects.
thanks for any help,
Janet
library(ggbio)
## make a simulated time series data set
df1 <- data.frame(time = 1:100, score = sin((1:100)/20)*10)
p1 <- qplot(data = df1, x = time, y = score, geom = "line")
df2 <- data.frame(time = 30:120, score = sin((30:120)/20)*10, value = rnorm(120-30 + 1))
p2 <- ggplot(data = df2, aes(x = time, y = score)) +
geom_line() + geom_point(size = 4, aes(color = value))
p3 <- p2 + theme(legend.position = "none")
## binding
tracks(p1, p2, p3)
sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggbio_1.34.0 ggplot2_3.2.1 BiocGenerics_0.32.0
loaded via a namespace (and not attached):
[1] ProtGenerics_1.18.0 bitops_1.0-6 matrixStats_0.55.0
[4] bit64_0.9-7 RColorBrewer_1.1-2 progress_1.2.2
[7] httr_1.4.1 GenomeInfoDb_1.22.0 tools_3.6.1
[10] backports_1.1.5 R6_2.4.1 rpart_4.1-15
[13] Hmisc_4.3-0 DBI_1.0.0 lazyeval_0.2.2
[16] colorspace_1.4-1 nnet_7.3-12 withr_2.1.2
[19] tidyselect_0.2.5 gridExtra_2.3 prettyunits_1.0.2
[22] GGally_1.4.0 bit_1.1-14 curl_4.2
[25] compiler_3.6.1 graph_1.64.0 Biobase_2.46.0
[28] htmlTable_1.13.2 DelayedArray_0.12.0 labeling_0.3
[31] rtracklayer_1.46.0 scales_1.1.0 checkmate_1.9.4
[34] RBGL_1.62.1 askpass_1.1 rappdirs_0.3.1
[37] stringr_1.4.0 digest_0.6.23 Rsamtools_2.2.1
[40] foreign_0.8-72 XVector_0.26.0 base64enc_0.1-3
[43] dichromat_2.0-0 pkgconfig_2.0.3 htmltools_0.4.0
[46] ensembldb_2.10.2 dbplyr_1.4.2 BSgenome_1.54.0
[49] htmlwidgets_1.5.1 rlang_0.4.2 rstudioapi_0.10
[52] RSQLite_2.1.2 farver_2.0.1 BiocParallel_1.20.0
[55] acepack_1.4.1 dplyr_0.8.3 VariantAnnotation_1.32.0
[58] RCurl_1.95-4.12 magrittr_1.5 GenomeInfoDbData_1.2.2
[61] Formula_1.2-3 Matrix_1.2-18 Rcpp_1.0.3
[64] munsell_0.5.0 S4Vectors_0.24.0 lifecycle_0.1.0
[67] stringi_1.4.3 SummarizedExperiment_1.16.0 zlibbioc_1.32.0
[70] plyr_1.8.4 BiocFileCache_1.10.2 grid_3.6.1
[73] blob_1.2.0 crayon_1.3.4 lattice_0.20-38
[76] Biostrings_2.54.0 splines_3.6.1 GenomicFeatures_1.38.0
[79] hms_0.5.2 zeallot_0.1.0 knitr_1.26
[82] pillar_1.4.2 GenomicRanges_1.38.0 reshape2_1.4.3
[85] biomaRt_2.42.0 stats4_3.6.1 XML_3.98-1.20
[88] glue_1.3.1 biovizBase_1.34.0 latticeExtra_0.6-28
[91] BiocManager_1.30.10 data.table_1.12.6 vctrs_0.2.0
[94] gtable_0.3.0 openssl_1.4.1 purrr_0.3.3
[97] reshape_0.8.8 assertthat_0.2.1 xfun_0.11
[100] AnnotationFilter_1.10.0 survival_3.1-7 OrganismDbi_1.28.0
[103] tibble_2.1.3 GenomicAlignments_1.22.1 AnnotationDbi_1.48.0
[106] memoise_1.1.0 IRanges_2.20.1 cluster_2.1.0
Thanks Michael - I couldn't quite tell how mature ggbio is. The vignette examples look nice, but I've been finding it a bit challenging to get it to look good with my data. I'm now trying to decide whether to stick to ggbio, or convert to dataframes and use regular ggplots: any thoughts?