ggtree icon indicating copy to clipboard operation
ggtree copied to clipboard

geom_hilight with gradient does not show anything

Open joelnitta opened this issue 3 years ago • 5 comments

Prerequisites

  • [x] Have you read Feedback and follow the guide?
    • [x] make sure your are using the latest release version
    • [x] read the documents
    • [x] google your question/issue

Describe you issue

  • [x] Make a reproducible example (e.g. 1)
  • [x] your code should contain comments to describe the problem (e.g. what expected and actually happened?)

Ask in right place

  • [x] for bugs or feature requests, post here (github issue)
  • [x] for questions, please post to google group

(BTW: the feedback link above is broken)

Using the example code in the help for geom_hilight() does not result in gradient rectangles.

library(ggtree)
#> ggtree v3.3.1  For help: https://yulab-smu.top/treedata-book/
#> 
#> If you use ggtree in published research, please cite the most appropriate paper(s):
#> 
#> 1. Guangchuang Yu. Using ggtree to visualize data on tree-like structures. Current Protocols in Bioinformatics. 2020, 69:e96. doi:10.1002/cpbi.96
#> 2. Guangchuang Yu, Tommy Tsan-Yuk Lam, Huachen Zhu, Yi Guan. Two methods for mapping and visualizing associated data on phylogeny using ggtree. Molecular Biology and Evolution. 2018, 35(12):3041-3043. doi:10.1093/molbev/msy194
#> 3. Guangchuang Yu, David Smith, Huachen Zhu, Yi Guan, Tommy Tsan-Yuk Lam. ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data. Methods in Ecology and Evolution. 2017, 8(1):28-36. doi:10.1111/2041-210X.12628
set.seed(102)
tree <- rtree(60)
p <- ggtree(tree)
p1 <- p + geom_hilight(node=62) + geom_hilight(node=88, fill="red")
p1

dat <- data.frame(id=c(62, 88), type=c("A", "B"))
p2 <- p + geom_hilight(data=dat, mapping=aes(node=id, fill=type))
p2

# display the high light layer with gradiental color rectangular.
p6 <- p + geom_hilight(data=dat, mapping=aes(node=id, fill=type), type = "gradient", alpha=0.68)
p6

p7 <- p + geom_hilight(data=dat, mapping=aes(node=id, fill=type), type = "gradient", gradient.direction="tr", alpha=0.68)
p7

Created on 2022-02-02 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.1.2 (2021-11-01)
#>  os       macOS Catalina 10.15.7
#>  system   x86_64, darwin17.0
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Asia/Tokyo
#>  date     2022-02-02
#>  pandoc   2.11.4 @ /Applications/RStudio.app/Contents/MacOS/pandoc/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  ! package      * version date (UTC) lib source
#>  P ape            5.6-1   2022-01-07 [?] CRAN (R 4.1.2)
#>  P aplot          0.1.2   2022-01-10 [?] CRAN (R 4.1.2)
#>  P assertthat     0.2.1   2019-03-21 [?] CRAN (R 4.1.0)
#>  P backports      1.4.1   2021-12-13 [?] CRAN (R 4.1.0)
#>  P cli            3.1.0   2021-10-27 [?] CRAN (R 4.1.0)
#>  P colorspace     2.0-2   2021-06-24 [?] CRAN (R 4.1.0)
#>  P crayon         1.4.2   2021-10-29 [?] CRAN (R 4.1.0)
#>  P curl           4.3.2   2021-06-23 [?] CRAN (R 4.1.0)
#>  P DBI            1.1.1   2021-01-15 [?] CRAN (R 4.1.0)
#>  P digest         0.6.29  2021-12-01 [?] CRAN (R 4.1.0)
#>  P dplyr          1.0.7   2021-06-18 [?] CRAN (R 4.1.0)
#>  P ellipsis       0.3.2   2021-04-29 [?] CRAN (R 4.1.0)
#>  P evaluate       0.14    2019-05-28 [?] CRAN (R 4.1.0)
#>  P fansi          0.5.0   2021-05-25 [?] CRAN (R 4.1.0)
#>  P farver         2.1.0   2021-02-28 [?] CRAN (R 4.1.0)
#>  P fastmap        1.1.0   2021-01-25 [?] CRAN (R 4.1.0)
#>  P fs             1.5.2   2021-12-08 [?] CRAN (R 4.1.0)
#>  P generics       0.1.1   2021-10-25 [?] CRAN (R 4.1.0)
#>  P ggfun          0.0.5   2022-01-20 [?] CRAN (R 4.1.2)
#>  P ggplot2        3.3.5   2021-06-25 [?] CRAN (R 4.1.0)
#>  P ggplotify      0.1.0   2021-09-02 [?] CRAN (R 4.1.0)
#>  P ggtree       * 3.3.1   2022-02-02 [?] Github (YuLab-SMU/ggtree@60be2d1)
#>  P glue           1.6.0   2021-12-17 [?] CRAN (R 4.1.0)
#>  P gridGraphics   0.5-1   2020-12-13 [?] CRAN (R 4.1.0)
#>  P gtable         0.3.0   2019-03-25 [?] CRAN (R 4.1.0)
#>  P highr          0.9     2021-04-16 [?] CRAN (R 4.1.0)
#>  P htmltools      0.5.2   2021-08-25 [?] CRAN (R 4.1.0)
#>  P httr           1.4.2   2020-07-20 [?] CRAN (R 4.1.0)
#>  P jsonlite       1.7.2   2020-12-09 [?] CRAN (R 4.1.0)
#>  P knitr          1.37    2021-12-16 [?] CRAN (R 4.1.0)
#>  P labeling       0.4.2   2020-10-20 [?] CRAN (R 4.1.0)
#>  P lattice        0.20-45 2021-09-22 [?] CRAN (R 4.1.2)
#>  P lazyeval       0.2.2   2019-03-15 [?] CRAN (R 4.1.0)
#>  P lifecycle      1.0.1   2021-09-24 [?] CRAN (R 4.1.0)
#>  P magrittr       2.0.1   2020-11-17 [?] CRAN (R 4.1.0)
#>  P mime           0.12    2021-09-28 [?] CRAN (R 4.1.0)
#>  P munsell        0.5.0   2018-06-12 [?] CRAN (R 4.1.0)
#>  P nlme           3.1-153 2021-09-07 [?] CRAN (R 4.1.2)
#>  P patchwork      1.1.1   2020-12-17 [?] CRAN (R 4.1.0)
#>  P pillar         1.6.4   2021-10-18 [?] CRAN (R 4.1.0)
#>  P pkgconfig      2.0.3   2019-09-22 [?] CRAN (R 4.1.0)
#>  P purrr          0.3.4   2020-04-17 [?] CRAN (R 4.1.0)
#>    R.cache        0.15.0  2021-04-30 [3] CRAN (R 4.1.0)
#>    R.methodsS3    1.8.1   2020-08-26 [3] CRAN (R 4.1.0)
#>    R.oo           1.24.0  2020-08-26 [3] CRAN (R 4.1.0)
#>    R.utils        2.11.0  2021-09-26 [3] CRAN (R 4.1.0)
#>  P R6             2.5.1   2021-08-19 [?] CRAN (R 4.1.0)
#>  P Rcpp           1.0.7   2021-07-07 [?] CRAN (R 4.1.0)
#>  P reprex         2.0.1   2021-08-05 [?] CRAN (R 4.1.0)
#>  P rlang          0.4.12  2021-10-18 [?] CRAN (R 4.1.0)
#>  P rmarkdown      2.11    2021-09-14 [?] CRAN (R 4.1.0)
#>  P rstudioapi     0.13    2020-11-12 [?] CRAN (R 4.1.0)
#>  P scales         1.1.1   2020-05-11 [?] CRAN (R 4.1.0)
#>    sessioninfo    1.2.2   2021-12-06 [3] CRAN (R 4.1.0)
#>  P stringi        1.7.6   2021-11-29 [?] CRAN (R 4.1.0)
#>  P stringr        1.4.0   2019-02-10 [?] CRAN (R 4.1.0)
#>    styler         1.6.2   2021-09-23 [3] CRAN (R 4.1.0)
#>  P tibble         3.1.6   2021-11-07 [?] CRAN (R 4.1.0)
#>  P tidyr          1.1.4   2021-09-27 [?] CRAN (R 4.1.0)
#>  P tidyselect     1.1.1   2021-04-30 [?] CRAN (R 4.1.0)
#>  P tidytree       0.3.7   2022-01-10 [?] CRAN (R 4.1.2)
#>  P treeio         1.19.1  2022-01-30 [?] Github (GuangchuangYu/treeio@976d564)
#>  P utf8           1.2.2   2021-07-24 [?] CRAN (R 4.1.0)
#>  P vctrs          0.3.8   2021-04-29 [?] CRAN (R 4.1.0)
#>  P withr          2.4.3   2021-11-30 [?] CRAN (R 4.1.0)
#>  P xfun           0.29    2021-12-14 [?] CRAN (R 4.1.0)
#>  P xml2           1.3.3   2021-11-30 [?] CRAN (R 4.1.0)
#>  P yaml           2.2.1   2020-02-01 [?] CRAN (R 4.1.0)
#>  P yulab.utils    0.0.4   2021-10-09 [?] CRAN (R 4.1.0)
#> 
#>  [1] /Users/joelnitta/repos/ftol_ms/renv/library/R-4.1/x86_64-apple-darwin17.0
#>  [2] /private/var/folders/gp/h66562zx3ps986y5z2jzrc0h0000gn/T/RtmpZnjeaH/renv-system-library
#>  [3] /Library/Frameworks/R.framework/Versions/4.1/Resources/library
#> 
#>  P ── Loaded and on-disk path mismatch.
#> 
#> ──────────────────────────────────────────────────────────────────────────────

joelnitta avatar Feb 02 '22 07:02 joelnitta

Hi, Thanks for the reprex. Use the parameter gradient =TRUE instead of type ='gradient'. The type option is used for the tree layout p+ geom_hilight(data=dat, aes(node=id, fill=type),extend=1 , gradient = TRUE) I am in Package ggtree version 3.1.5.900 and the manual of the function is clear to me. Does it answer your question ?

BastienBennetot avatar Feb 02 '22 07:02 BastienBennetot

Hi, Thanks for the reprex. Use the parameter gradient =TRUE instead of type ='gradient'. The type option is used for the tree layout p+ geom_hilight(data=dat, aes(node=id, fill=type),extend=1 , gradient = TRUE) I am in Package ggtree version 3.1.5.900 and the manual of the function is clear to me. Does it answer your question ?

BastienBennetot avatar Feb 02 '22 07:02 BastienBennetot

Thanks for the quick reply. That doesn't seem to work for me. Perhaps it is because you are using an older version (3.1.5.900 vs 3.3.1). If so, it needs to be fixed in the newer version.

library(ggtree)
#> ggtree v3.3.1  For help: https://yulab-smu.top/treedata-book/
#> 
#> If you use ggtree in published research, please cite the most appropriate paper(s):
#> 
#> 1. Guangchuang Yu. Using ggtree to visualize data on tree-like structures. Current Protocols in Bioinformatics. 2020, 69:e96. doi:10.1002/cpbi.96
#> 2. Guangchuang Yu, Tommy Tsan-Yuk Lam, Huachen Zhu, Yi Guan. Two methods for mapping and visualizing associated data on phylogeny using ggtree. Molecular Biology and Evolution. 2018, 35(12):3041-3043. doi:10.1093/molbev/msy194
#> 3. Guangchuang Yu, David Smith, Huachen Zhu, Yi Guan, Tommy Tsan-Yuk Lam. ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data. Methods in Ecology and Evolution. 2017, 8(1):28-36. doi:10.1111/2041-210X.12628
set.seed(102)
tree <- rtree(60)
p <- ggtree(tree)
dat <- data.frame(id=c(62, 88), type=c("A", "B"))
p + geom_hilight(data=dat, aes(node=id, fill=type),extend=1 , gradient = TRUE)

Created on 2022-02-02 by the reprex package (v2.0.1)

joelnitta avatar Feb 02 '22 08:02 joelnitta

Now, the gradient highlight only can work on the Linux Platform. Or using svg on Windows. You can refer to the answer

xiangpin avatar Feb 02 '22 12:02 xiangpin

Thanks, I will try it on linux

joelnitta avatar Feb 04 '22 22:02 joelnitta