ggcoverage icon indicating copy to clipboard operation
ggcoverage copied to clipboard

Overlapping labels

Open SPPearce opened this issue 2 years ago • 3 comments

Hi,

I've just tried your package and like the idea, but I'm running into an issue with overlapping gene names. I'm trying to visualise copy number changes over medium-sized regions (say a Mb or two), and the gene names are ending up running into each other. Is it possible to make the genes go onto different lines when this happens, as happens when the genes are physically overlapping?

Here is an example, where OXCT2 and BMP8B physically overlap, so they are placed on separate lines. But HEYL, NT5C1A and HPCAL4 don't physically overlap, it is just the label that does.

library(plyranges)
library(tidyverse)
library(ggcoverage)
#> Registered S3 method overwritten by 'GGally':
#>   method from   
#>   +.gg   ggplot2
#> Warning: replacing previous import 'ggplot2::annotate' by 'ggpp::annotate' when
#> loading 'ggcoverage'

my.track.data <- data.frame(seqnames = "chr1", start = 39500000, end = 40000000, 
                            score = 1, Type = "Sample1")

my.gtf.gr <- tribble(~seqnames,~start,~end, ~strand, ~gene_name,
                     "chr1",39623435,39639643,"+","HEYL",
                     "chr1",39659121,39672038,"-","NT5C1A",
                     "chr1",39678648,39691485,"+","HPCAL4",
                     "chr1",39692182,39763914,"+","PPIE",
                     "chr1",39757182,39788865,"-","BMP8B",
                     "chr1",39769523,39771348,"+","OXCT2") %>%
  mutate(gene_biotype = "protein_coding",type = "gene") %>%
  as_granges()

ggplot() +
  geom_coverage(data = my.track.data ) +
  geom_gene(my.gtf.gr) 
#> Warning in ggplot_add.gene(object, p, objectname): No UTR detected in provided
#> GTF!

Created on 2023-08-14 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.2.3 (2023-03-15)
#>  os       macOS Big Sur ... 10.16
#>  system   x86_64, darwin17.0
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Europe/London
#>  date     2023-08-14
#>  pandoc   2.19.2 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package              * version   date (UTC) lib source
#>  ade4                   1.7-22    2023-02-06 [1] CRAN (R 4.2.0)
#>  AnnotationDbi          1.60.2    2023-03-10 [1] Bioconductor
#>  AnnotationFilter       1.22.0    2022-11-01 [1] Bioconductor
#>  backports              1.4.1     2021-12-13 [1] CRAN (R 4.2.0)
#>  base64enc              0.1-3     2015-07-28 [1] CRAN (R 4.2.0)
#>  Biobase                2.58.0    2022-11-01 [1] Bioconductor
#>  BiocFileCache          2.6.1     2023-02-17 [1] Bioconductor
#>  BiocGenerics         * 0.44.0    2022-11-01 [1] Bioconductor
#>  BiocIO                 1.8.0     2022-11-01 [1] Bioconductor
#>  BiocManager            1.30.20   2023-02-24 [1] CRAN (R 4.2.0)
#>  BiocParallel           1.32.6    2023-03-17 [1] Bioconductor
#>  biomaRt                2.54.1    2023-03-20 [1] Bioconductor
#>  Biostrings             2.66.0    2022-11-01 [1] Bioconductor
#>  biovizBase             1.46.0    2022-11-01 [1] Bioconductor
#>  bit                    4.0.5     2022-11-15 [1] CRAN (R 4.2.0)
#>  bit64                  4.0.5     2020-08-30 [1] CRAN (R 4.2.0)
#>  bitops                 1.0-7     2021-04-24 [1] CRAN (R 4.2.0)
#>  blob                   1.2.4     2023-03-17 [1] CRAN (R 4.2.0)
#>  BSgenome               1.66.3    2023-02-16 [1] Bioconductor
#>  cachem                 1.0.8     2023-05-01 [1] CRAN (R 4.2.0)
#>  checkmate              2.2.0     2023-04-27 [1] CRAN (R 4.2.0)
#>  cli                    3.6.1     2023-03-23 [1] CRAN (R 4.2.0)
#>  cluster                2.1.4     2022-08-22 [1] CRAN (R 4.2.3)
#>  codetools              0.2-19    2023-02-01 [1] CRAN (R 4.2.3)
#>  colorspace             2.1-0     2023-01-23 [1] CRAN (R 4.2.0)
#>  crayon                 1.5.2     2022-09-29 [1] CRAN (R 4.2.0)
#>  curl                   5.0.0     2023-01-12 [1] CRAN (R 4.2.0)
#>  data.table             1.14.8    2023-02-17 [1] CRAN (R 4.2.0)
#>  DBI                    1.1.3     2022-06-18 [1] CRAN (R 4.2.0)
#>  dbplyr                 2.3.2     2023-03-21 [1] CRAN (R 4.2.0)
#>  DelayedArray           0.24.0    2022-11-01 [1] Bioconductor
#>  dichromat              2.0-0.1   2022-05-02 [1] CRAN (R 4.2.0)
#>  digest                 0.6.31    2022-12-11 [1] CRAN (R 4.2.0)
#>  dplyr                * 1.1.2     2023-04-20 [1] CRAN (R 4.2.0)
#>  ensembldb              2.22.0    2022-11-01 [1] Bioconductor
#>  evaluate               0.21      2023-05-05 [1] CRAN (R 4.2.0)
#>  fansi                  1.0.4     2023-01-22 [1] CRAN (R 4.2.0)
#>  farver                 2.1.1     2022-07-06 [1] CRAN (R 4.2.0)
#>  fastmap                1.1.1     2023-02-24 [1] CRAN (R 4.2.0)
#>  filelock               1.0.2     2018-10-05 [1] CRAN (R 4.2.0)
#>  forcats              * 1.0.0     2023-01-29 [1] CRAN (R 4.2.0)
#>  foreign                0.8-84    2022-12-06 [1] CRAN (R 4.2.3)
#>  Formula                1.2-5     2023-02-24 [1] CRAN (R 4.2.0)
#>  fs                     1.6.2     2023-04-25 [1] CRAN (R 4.2.0)
#>  generics               0.1.3     2022-07-05 [1] CRAN (R 4.2.0)
#>  GenomeInfoDb         * 1.34.9    2023-02-02 [1] Bioconductor
#>  GenomeInfoDbData       1.2.9     2023-04-11 [1] Bioconductor
#>  GenomeMatrix           0.99.3    2023-08-11 [1] Github (areyesq89/GenomeMatrix@102c273)
#>  GenomicAlignments      1.34.1    2023-03-09 [1] Bioconductor
#>  GenomicFeatures        1.50.4    2023-01-24 [1] Bioconductor
#>  GenomicRanges        * 1.50.2    2022-12-16 [1] Bioconductor
#>  GGally                 2.1.2     2021-06-21 [1] CRAN (R 4.2.0)
#>  ggbio                  1.46.0    2022-11-01 [1] Bioconductor
#>  ggcoverage           * 1.2.0     2023-08-11 [1] Github (showteeth/ggcoverage@c37c0cb)
#>  ggforce                0.4.1     2022-10-04 [1] CRAN (R 4.2.0)
#>  ggh4x                  0.2.5     2023-07-15 [1] CRAN (R 4.2.0)
#>  ggpattern              1.0.1     2022-11-09 [1] CRAN (R 4.2.0)
#>  ggplot2              * 3.4.2     2023-04-03 [1] CRAN (R 4.2.0)
#>  ggpp                   0.5.3     2023-07-16 [1] CRAN (R 4.2.0)
#>  ggrepel                0.9.3     2023-02-03 [1] CRAN (R 4.2.0)
#>  glue                   1.6.2     2022-02-24 [1] CRAN (R 4.2.0)
#>  graph                  1.76.0    2022-11-01 [1] Bioconductor
#>  gridExtra              2.3       2017-09-09 [1] CRAN (R 4.2.0)
#>  gtable                 0.3.3     2023-03-21 [1] CRAN (R 4.2.0)
#>  HiCBricks              1.16.0    2022-11-01 [1] Bioconductor
#>  highr                  0.10      2022-12-22 [1] CRAN (R 4.2.0)
#>  Hmisc                  5.1-0     2023-05-08 [1] CRAN (R 4.2.0)
#>  hms                    1.1.3     2023-03-21 [1] CRAN (R 4.2.0)
#>  htmlTable              2.4.1     2022-07-07 [1] CRAN (R 4.2.0)
#>  htmltools              0.5.5     2023-03-23 [1] CRAN (R 4.2.0)
#>  htmlwidgets            1.6.2     2023-03-17 [1] CRAN (R 4.2.0)
#>  httr                   1.4.6     2023-05-08 [1] CRAN (R 4.2.0)
#>  IRanges              * 2.32.0    2022-11-01 [1] Bioconductor
#>  jsonlite               1.8.5     2023-06-05 [1] CRAN (R 4.2.3)
#>  KEGGREST               1.38.0    2022-11-01 [1] Bioconductor
#>  knitr                  1.43      2023-05-25 [1] CRAN (R 4.2.0)
#>  labeling               0.4.2     2020-10-20 [1] CRAN (R 4.2.0)
#>  lattice                0.21-8    2023-04-05 [1] CRAN (R 4.2.0)
#>  lazyeval               0.2.2     2019-03-15 [1] CRAN (R 4.2.0)
#>  lifecycle              1.0.3     2022-10-07 [1] CRAN (R 4.2.0)
#>  lubridate            * 1.9.2     2023-02-10 [1] CRAN (R 4.2.0)
#>  magrittr               2.0.3     2022-03-30 [1] CRAN (R 4.2.0)
#>  MASS                   7.3-60    2023-05-04 [1] CRAN (R 4.2.0)
#>  Matrix                 1.5-4.1   2023-05-18 [1] CRAN (R 4.2.0)
#>  MatrixGenerics         1.10.0    2022-11-01 [1] Bioconductor
#>  matrixStats            1.0.0     2023-06-02 [1] CRAN (R 4.2.0)
#>  memoise                2.0.1     2021-11-26 [1] CRAN (R 4.2.0)
#>  munsell                0.5.0     2018-06-12 [1] CRAN (R 4.2.0)
#>  nnet                   7.3-19    2023-05-03 [1] CRAN (R 4.2.0)
#>  openxlsx               4.2.5.2   2023-02-06 [1] CRAN (R 4.2.0)
#>  OrganismDbi            1.40.0    2022-11-01 [1] Bioconductor
#>  patchwork              1.1.2     2022-08-19 [1] CRAN (R 4.2.0)
#>  pillar                 1.9.0     2023-03-22 [1] CRAN (R 4.2.0)
#>  pkgconfig              2.0.3     2019-09-22 [1] CRAN (R 4.2.0)
#>  plyr                   1.8.8     2022-11-11 [1] CRAN (R 4.2.0)
#>  plyranges            * 1.18.0    2022-11-01 [1] Bioconductor
#>  png                    0.1-8     2022-11-29 [1] CRAN (R 4.2.0)
#>  polyclip               1.10-4    2022-10-20 [1] CRAN (R 4.2.0)
#>  polynom                1.4-1     2022-04-11 [1] CRAN (R 4.2.0)
#>  prettyunits            1.1.1     2020-01-24 [1] CRAN (R 4.2.0)
#>  progress               1.2.2     2019-05-16 [1] CRAN (R 4.2.0)
#>  ProtGenerics           1.30.0    2022-11-01 [1] Bioconductor
#>  purrr                * 1.0.1     2023-01-10 [1] CRAN (R 4.2.0)
#>  R.methodsS3            1.8.2     2022-06-13 [1] CRAN (R 4.2.0)
#>  R.oo                   1.25.0    2022-06-12 [1] CRAN (R 4.2.0)
#>  R.utils                2.12.2    2022-11-11 [1] CRAN (R 4.2.0)
#>  R6                     2.5.1     2021-08-19 [1] CRAN (R 4.2.0)
#>  rappdirs               0.3.3     2021-01-31 [1] CRAN (R 4.2.0)
#>  RBGL                   1.74.0    2022-11-01 [1] Bioconductor
#>  RColorBrewer           1.1-3     2022-04-03 [1] CRAN (R 4.2.0)
#>  Rcpp                   1.0.11    2023-07-06 [1] CRAN (R 4.2.0)
#>  RCurl                  1.98-1.12 2023-03-27 [1] CRAN (R 4.2.0)
#>  readr                * 2.1.4     2023-02-10 [1] CRAN (R 4.2.0)
#>  reprex                 2.0.2     2022-08-17 [1] CRAN (R 4.2.0)
#>  reshape                0.8.9     2022-04-12 [1] CRAN (R 4.2.0)
#>  reshape2               1.4.4     2020-04-09 [1] CRAN (R 4.2.0)
#>  restfulr               0.0.15    2022-06-16 [1] CRAN (R 4.2.0)
#>  rhdf5                  2.42.1    2023-04-07 [1] Bioconductor
#>  rhdf5filters           1.10.1    2023-03-24 [1] Bioconductor
#>  Rhdf5lib               1.20.0    2022-11-01 [1] Bioconductor
#>  rjson                  0.2.21    2022-01-09 [1] CRAN (R 4.2.0)
#>  rlang                  1.1.1     2023-04-28 [1] CRAN (R 4.2.0)
#>  rmarkdown              2.22      2023-06-01 [1] CRAN (R 4.2.0)
#>  rpart                  4.1.19    2022-10-21 [1] CRAN (R 4.2.3)
#>  Rsamtools              2.14.0    2022-11-01 [1] Bioconductor
#>  RSQLite                2.3.1     2023-04-03 [1] CRAN (R 4.2.0)
#>  rstudioapi             0.14      2022-08-22 [1] CRAN (R 4.2.0)
#>  rtracklayer            1.58.0    2022-11-01 [1] Bioconductor
#>  S4Vectors            * 0.36.2    2023-02-26 [1] Bioconductor
#>  scales                 1.2.1     2022-08-20 [1] CRAN (R 4.2.0)
#>  seqinr                 4.2-30    2023-04-05 [1] CRAN (R 4.2.0)
#>  sessioninfo            1.2.2     2021-12-06 [1] CRAN (R 4.2.0)
#>  stringi                1.7.12    2023-01-11 [1] CRAN (R 4.2.0)
#>  stringr              * 1.5.0     2022-12-02 [1] CRAN (R 4.2.0)
#>  SummarizedExperiment   1.28.0    2022-11-01 [1] Bioconductor
#>  tibble               * 3.2.1     2023-03-20 [1] CRAN (R 4.2.0)
#>  tidyr                * 1.3.0     2023-01-24 [1] CRAN (R 4.2.0)
#>  tidyselect             1.2.0     2022-10-10 [1] CRAN (R 4.2.0)
#>  tidyverse            * 2.0.0     2023-02-22 [1] CRAN (R 4.2.0)
#>  timechange             0.2.0     2023-01-11 [1] CRAN (R 4.2.0)
#>  tweenr                 2.0.2     2022-09-06 [1] CRAN (R 4.2.0)
#>  tzdb                   0.4.0     2023-05-12 [1] CRAN (R 4.2.0)
#>  utf8                   1.2.3     2023-01-31 [1] CRAN (R 4.2.0)
#>  VariantAnnotation      1.44.1    2023-02-15 [1] Bioconductor
#>  vctrs                  0.6.3     2023-06-14 [1] CRAN (R 4.2.0)
#>  viridis                0.6.3     2023-05-03 [1] CRAN (R 4.2.0)
#>  viridisLite            0.4.2     2023-05-02 [1] CRAN (R 4.2.0)
#>  withr                  2.5.0     2022-03-03 [1] CRAN (R 4.2.0)
#>  xfun                   0.40      2023-08-09 [1] CRAN (R 4.2.0)
#>  XML                    3.99-0.14 2023-03-19 [1] CRAN (R 4.2.0)
#>  xml2                   1.3.4     2023-04-27 [1] CRAN (R 4.2.0)
#>  XVector                0.38.0    2022-11-01 [1] Bioconductor
#>  yaml                   2.3.7     2023-01-23 [1] CRAN (R 4.2.0)
#>  zip                    2.3.0     2023-04-17 [1] CRAN (R 4.2.0)
#>  zlibbioc               1.44.0    2022-11-01 [1] Bioconductor
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.2/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

SPPearce avatar Aug 13 '23 18:08 SPPearce

Hi, Can you show me the version you used? In the latest version (remotes::install_github("showteeth/ggcoverage")), I added overlap.style to control the gene overlap style. By default, each gene occupies a single line just like this.

YB

showteeth avatar Aug 14 '23 02:08 showteeth

Hi,

I have updated the code above to include the sessionInfo. I am using R 4.2.0, with the most recent version of ggcoverage installed from github this week.

SPPearce avatar Aug 14 '23 06:08 SPPearce

Thanks for your timely feedback. This is indeed a bug, I will update it as soon as possible.

showteeth avatar Aug 14 '23 08:08 showteeth

issue will be fixed with next release; in the mean time you can use the latest commit from my dev branch.

m-jahn avatar Apr 19 '24 13:04 m-jahn