Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

bulk_clones plot "CNV state" legend colors #182

Closed
igordot opened this issue Apr 9, 2024 · 7 comments
Closed

bulk_clones plot "CNV state" legend colors #182

igordot opened this issue Apr 9, 2024 · 7 comments
Labels
fixed Fixed in upcoming version

Comments

@igordot
Copy link
Contributor

igordot commented Apr 9, 2024

It seems that the bulk_clones plot is sometimes missing the CNV state colors legend. Is that expected or a bug?

For example, here is the plot from the mouse tutorial with a proper legend:
image

Compare that to the Interpreting Numbat results vignette where the legend only has two colors:
image

@teng-gao
Copy link
Collaborator

Upgrading from ggplot2 3.4.x -> 3.5.0 caused this .. I raised an issue on their github repo. hopefully they fix it soon.

@igordot
Copy link
Contributor Author

igordot commented Apr 10, 2024

Thanks for the update! I had some other packages break with ggplot2 3.5.0 as well.

@teunbrand
Copy link

Hi, I just stumbled across this by accident.
This is intended, and ggplot2 is not going to remedy this issue.
If you want to include all keys of a layer regardless of whether that value is present in the data, you should use show.legend = TRUE.
By default, only keys are shown for which values exist in the data.

@igordot
Copy link
Contributor Author

igordot commented Jun 5, 2024

Curiously, I've seen some packages add specific workarounds related to ggplot2 3.5, so it's definitely a widespread issue without a simple elegant fix. For example, hrbrthemes (with over 1k GitHub stars): https://github.com/hrbrmstr/hrbrthemes/blob/6417996c2931b3fa84102b5034a42a920c91fdb9/R/color.r#L20-L23

@teunbrand
Copy link

The code you linked to is to silence soft-deprecation warnings, which is unrelated to legend keys. The way to restore old behaviour is to use show.legend argument in layers, which is simple enough.

@trekonom
Copy link

trekonom commented Sep 8, 2024

As an illustration of the fix proposed by @teunbrand and as a possible workaround one can manually set show.legend=TRUE for the geom_point layer like so:

library(numbat)
#> Loading required package: Matrix
library(dplyr, warn=FALSE)
nb <- readRDS(url("http://pklab.med.harvard.edu/teng/data/nb_TNBC1.rds"))

p <- nb$bulk_clones %>%
  filter(n_cells > 50) %>%
  plot_bulks(
    min_LLR = 10, # filtering CNVs by evidence
    legend = TRUE
  )

for (i in seq_along(p)) {
  p[[i]]$layers[[2]]$show.legend <- TRUE
}

p

Created on 2024-09-08 with reprex v2.1.1

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.4.1 (2024-06-14)
#>  os       macOS Sonoma 14.6.1
#>  system   aarch64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Europe/Berlin
#>  date     2024-09-08
#>  pandoc   3.1.11 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/aarch64/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package      * version    date (UTC) lib source
#>  ape            5.8        2024-04-11 [1] CRAN (R 4.4.0)
#>  aplot          0.2.3      2024-06-17 [1] CRAN (R 4.4.0)
#>  cachem         1.1.0      2024-05-16 [1] CRAN (R 4.4.0)
#>  cli            3.6.3      2024-06-21 [1] CRAN (R 4.4.0)
#>  codetools      0.2-20     2024-03-31 [1] CRAN (R 4.4.1)
#>  colorspace     2.1-1      2024-07-26 [1] CRAN (R 4.4.0)
#>  curl           5.2.2      2024-08-26 [1] CRAN (R 4.4.1)
#>  data.table     1.15.4     2024-03-30 [1] CRAN (R 4.4.0)
#>  digest         0.6.37     2024-08-19 [1] CRAN (R 4.4.1)
#>  dplyr        * 1.1.4      2023-11-17 [1] CRAN (R 4.4.0)
#>  evaluate       0.24.0     2024-06-10 [1] CRAN (R 4.4.0)
#>  fansi          1.0.6      2023-12-08 [1] CRAN (R 4.4.0)
#>  farver         2.1.2      2024-05-13 [1] CRAN (R 4.4.0)
#>  fastmap        1.2.0      2024-05-15 [1] CRAN (R 4.4.0)
#>  fastmatch      1.1-4      2023-08-18 [1] CRAN (R 4.4.0)
#>  fs             1.6.4      2024-04-25 [1] CRAN (R 4.4.0)
#>  generics       0.1.3      2022-07-05 [1] CRAN (R 4.4.0)
#>  ggforce        0.4.2      2024-02-19 [1] CRAN (R 4.4.0)
#>  ggfun          0.1.5      2024-05-28 [1] CRAN (R 4.4.0)
#>  ggplot2        3.5.1      2024-04-23 [1] CRAN (R 4.4.0)
#>  ggplotify      0.1.2      2023-08-09 [1] CRAN (R 4.4.0)
#>  ggraph         2.2.1      2024-03-07 [1] CRAN (R 4.4.0)
#>  ggrepel        0.9.5.9999 2024-09-03 [1] Github (slowkow/ggrepel@0f34805)
#>  ggtree         3.12.0     2024-04-30 [1] Bioconductor 3.19 (R 4.4.0)
#>  glue           1.7.0      2024-01-09 [1] CRAN (R 4.4.0)
#>  graphlayouts   1.1.1      2024-03-09 [1] CRAN (R 4.4.0)
#>  gridExtra      2.3        2017-09-09 [1] CRAN (R 4.4.0)
#>  gridGraphics   0.5-1      2020-12-13 [1] CRAN (R 4.4.0)
#>  gtable         0.3.5      2024-04-22 [1] CRAN (R 4.4.0)
#>  hahmmr         1.0.0      2023-10-25 [1] CRAN (R 4.4.0)
#>  highr          0.11       2024-05-26 [1] CRAN (R 4.4.0)
#>  htmltools      0.5.8.1    2024-04-04 [1] CRAN (R 4.4.0)
#>  httr2          1.0.2      2024-07-16 [1] CRAN (R 4.4.0)
#>  igraph         2.0.3      2024-03-13 [1] CRAN (R 4.4.0)
#>  jsonlite       1.8.8      2023-12-04 [1] CRAN (R 4.4.0)
#>  knitr          1.48       2024-07-07 [1] CRAN (R 4.4.0)
#>  labeling       0.4.3      2023-08-29 [1] CRAN (R 4.4.0)
#>  lattice        0.22-6     2024-03-20 [1] CRAN (R 4.4.1)
#>  lazyeval       0.2.2      2019-03-15 [1] CRAN (R 4.4.0)
#>  lifecycle      1.0.4      2023-11-07 [1] CRAN (R 4.4.0)
#>  logger         0.3.0      2024-03-05 [1] CRAN (R 4.4.0)
#>  magrittr       2.0.3      2022-03-30 [1] CRAN (R 4.4.0)
#>  MASS           7.3-61     2024-06-13 [1] CRAN (R 4.4.0)
#>  Matrix       * 1.7-0      2024-04-26 [1] CRAN (R 4.4.1)
#>  memoise        2.0.1      2021-11-26 [1] CRAN (R 4.4.0)
#>  munsell        0.5.1      2024-04-01 [1] CRAN (R 4.4.0)
#>  nlme           3.1-166    2024-08-14 [1] CRAN (R 4.4.0)
#>  numbat       * 1.4.0      2024-02-23 [1] CRAN (R 4.4.0)
#>  parallelDist   0.2.6      2022-02-03 [1] CRAN (R 4.4.0)
#>  patchwork      1.2.0      2024-01-08 [1] CRAN (R 4.4.0)
#>  phangorn       2.11.1     2023-01-23 [1] CRAN (R 4.4.0)
#>  pillar         1.9.0      2023-03-22 [1] CRAN (R 4.4.0)
#>  pkgconfig      2.0.3      2019-09-22 [1] CRAN (R 4.4.0)
#>  polyclip       1.10-7     2024-07-23 [1] CRAN (R 4.4.0)
#>  purrr          1.0.2      2023-08-10 [1] CRAN (R 4.4.0)
#>  quadprog       1.5-8      2019-11-20 [1] CRAN (R 4.4.0)
#>  R6             2.5.1      2021-08-19 [1] CRAN (R 4.4.0)
#>  rappdirs       0.3.3      2021-01-31 [1] CRAN (R 4.4.0)
#>  Rcpp           1.0.13     2024-07-17 [1] CRAN (R 4.4.0)
#>  RcppParallel   5.1.9      2024-08-19 [1] CRAN (R 4.4.1)
#>  reprex         2.1.1      2024-07-06 [1] CRAN (R 4.4.0)
#>  RhpcBLASctl    0.23-42    2023-02-11 [1] CRAN (R 4.4.0)
#>  rlang          1.1.4      2024-06-04 [1] CRAN (R 4.4.0)
#>  rmarkdown      2.28       2024-08-17 [1] CRAN (R 4.4.0)
#>  rstudioapi     0.16.0     2024-03-24 [1] CRAN (R 4.4.0)
#>  scales         1.3.0      2023-11-28 [1] CRAN (R 4.4.0)
#>  scistreer      1.2.0      2023-06-15 [1] CRAN (R 4.4.0)
#>  sessioninfo    1.2.2      2021-12-06 [1] CRAN (R 4.4.0)
#>  stringi        1.8.4      2024-05-06 [1] CRAN (R 4.4.0)
#>  stringr        1.5.1      2023-11-14 [1] CRAN (R 4.4.0)
#>  tibble         3.2.1      2023-03-20 [1] CRAN (R 4.4.0)
#>  tidygraph      1.3.1      2024-01-30 [1] CRAN (R 4.4.0)
#>  tidyr          1.3.1      2024-01-24 [1] CRAN (R 4.4.0)
#>  tidyselect     1.2.1      2024-03-11 [1] CRAN (R 4.4.0)
#>  tidytree       0.4.6      2023-12-12 [1] CRAN (R 4.4.0)
#>  treeio         1.28.0     2024-04-30 [1] Bioconductor 3.19 (R 4.4.0)
#>  tweenr         2.0.3      2024-02-26 [1] CRAN (R 4.4.0)
#>  utf8           1.2.4      2023-10-22 [1] CRAN (R 4.4.0)
#>  vctrs          0.6.5      2023-12-01 [1] CRAN (R 4.4.0)
#>  viridis        0.6.5      2024-01-29 [1] CRAN (R 4.4.0)
#>  viridisLite    0.4.2      2023-05-02 [1] CRAN (R 4.4.0)
#>  withr          3.0.1      2024-07-31 [1] CRAN (R 4.4.0)
#>  xfun           0.47       2024-08-17 [1] CRAN (R 4.4.0)
#>  xml2           1.3.6      2023-12-04 [1] CRAN (R 4.4.0)
#>  yaml           2.3.10     2024-07-26 [1] CRAN (R 4.4.0)
#>  yulab.utils    0.1.6      2024-08-17 [1] CRAN (R 4.4.0)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

@teng-gao teng-gao added the tofix label Sep 18, 2024
teng-gao added a commit that referenced this issue Sep 18, 2024
@teng-gao
Copy link
Collaborator

Thanks @teunbrand @trekonom for the solution. Fixed in v1.4.2

@teng-gao teng-gao added fixed Fixed in upcoming version and removed tofix labels Sep 18, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
fixed Fixed in upcoming version
Projects
None yet
Development

No branches or pull requests

4 participants