ggtree icon indicating copy to clipboard operation
ggtree copied to clipboard

geom_nodelab reports an error, when using the offset argument.

Open FelixErnst opened this issue 4 years ago • 7 comments
trafficstars

Hi,

geom_nodelab reports an error, when using the offset argument.

> nwk <- system.file("extdata", "sample.nwk", package="treeio")
> tree <- read.tree(nwk)
> td <- as_tibble(tree)
> td$label <- LETTERS[seq.int(1L, nrow(td))]
> # works
> ggplot(tidytree::as.treedata(td), aes(x, y)) + geom_tree() + theme_tree()
> # works
> ggplot(tidytree::as.treedata(td), aes(x, y)) + geom_tree() + theme_tree() + geom_tiplab(offset = .1)
> # doesn't work
> ggplot(tidytree::as.treedata(td), aes(x, y)) + geom_tree() + theme_tree() + geom_tiplab(offset = .1) + geom_nodelab(offset = .1)
Error in geom_tiplab(mapping, offset = nudge_x, nudge_y = nudge_y, geom = geom,  : 
  formal argument "offset" matched by multiple actual arguments

I am not sure, whether the offset option should be supported by geom_nodelab, but I guess so. In any event the error or error message are wrong and point to an underlying mix up of arguments.

Is something, you would regard as worth fixing and fixable? Thanks for any help and/or advice.

Felix

edit:

sessionInfo
> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)

Matrix products: default

locale: [1] LC_COLLATE=English_Germany.1252 LC_CTYPE=English_Germany.1252 LC_MONETARY=English_Germany.1252 LC_NUMERIC=C LC_TIME=English_Germany.1252

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

other attached packages: [1] ggtree_2.4.0 tibble_3.0.4 miaViz_0.0.0.9000 ggplot2_3.3.2 mia_0.0.0.9002
[6] MicrobiomeExperiment_0.99.0.9014 Biostrings_2.58.0 XVector_0.30.0 TreeSummarizedExperiment_1.6.0 SingleCellExperiment_1.12.0
[11] SummarizedExperiment_1.20.0 Biobase_2.50.0 GenomicRanges_1.42.0 GenomeInfoDb_1.26.0 IRanges_2.24.0
[16] S4Vectors_0.28.0 BiocGenerics_0.36.0 MatrixGenerics_1.2.0 matrixStats_0.57.0

loaded via a namespace (and not attached): [1] viridis_0.5.1 BiocSingular_1.6.0 tidyr_1.1.2 jsonlite_1.7.1 viridisLite_0.3.0 DelayedMatrixStats_1.12.0 scuttle_1.0.0
[8] assertthat_0.2.1 BiocManager_1.30.10 rvcheck_0.1.8 GenomeInfoDbData_1.2.4 vipor_0.4.5 pillar_1.4.6 lattice_0.20-41
[15] glue_1.4.2 beachmat_2.6.0 digest_0.6.27 colorspace_1.4-1 Matrix_1.2-18 pkgconfig_2.0.3 zlibbioc_1.36.0
[22] purrr_0.3.4 patchwork_1.0.1 tidytree_0.3.3 scales_1.1.1 BiocParallel_1.24.0 generics_0.1.0 farver_2.0.3
[29] ellipsis_0.3.1 withr_2.3.0 lazyeval_0.2.2 cli_2.1.0 magrittr_1.5 crayon_1.3.4 fansi_0.4.1
[36] nlme_3.1-150 beeswarm_0.2.3 tools_4.0.3 scater_1.18.0 lifecycle_0.2.0 stringr_1.4.0 aplot_0.0.6
[43] munsell_0.5.0 DelayedArray_0.16.0 irlba_2.3.3 compiler_4.0.3 rsvd_1.0.3 rlang_0.4.8 grid_4.0.3
[50] RCurl_1.98-1.2 BiocNeighbors_1.8.0 rstudioapi_0.11 bitops_1.0-6 labeling_0.4.2 gtable_0.3.0 R6_2.5.0
[57] gridExtra_2.3 dplyr_1.0.2 treeio_1.14.0 ape_5.4-1 stringi_1.5.3 ggbeeswarm_0.6.0 Rcpp_1.0.5
[64] vctrs_0.3.4 tidyselect_1.1.0 sparseMatrixStats_1.2.0

FelixErnst avatar Nov 24 '20 10:11 FelixErnst

please use nudge_x in geom_nodelab instead of offset.

xiangpin avatar Nov 24 '20 12:11 xiangpin

How does this translate, when I plot a circular tree plot? From what I understood there used to be a geom_nodelab2 function, but that seams to be deprecated.

Should I also use nudge_x for geom_tiplab?

Also it seams that geom_nodelab does not have an effect for circular plots. Can you comment on that? Is this to be expected?

FelixErnst avatar Nov 24 '20 13:11 FelixErnst

In geom_tiplab, you should use offset to control the distance. It seems that the position of node labels might need to be adjusted horizontally (nudge_x) and vertically (nudge_y), and nudge_x and nudge_y inherits geom_text of ggplot2.

geom_nodelab has supported both rectangular and circluar layout. So geom_nodelab2 was deprecated.

xiangpin avatar Nov 24 '20 13:11 xiangpin

This doesn't work.

Starting from the example given above:

ggplot(tidytree::as.treedata(td), aes(x, y)) + geom_tree(layout="circular") + theme_tree()

does not produce a circular plot as suggested by ?geom_tree. (The layout argument is shown there). However,

ggtree(tidytree::as.treedata(td), layout="circular") + theme_tree() + geom_nodelab()

produces a circular plot, but no node labels are shown.

I would say something is going on in the state of denmark.

FelixErnst avatar Nov 24 '20 14:11 FelixErnst

the circular layout is produced by :

ggplot(tree) + geom_tree() + layout_circular()

GuangchuangYu avatar Nov 25 '20 01:11 GuangchuangYu

the circular layout is produced by :

ggplot(tree) + geom_tree() + layout_circular()

So the layout argument for geom_tree is not used in any event? This seams to be man page issue then.

FelixErnst avatar Nov 25 '20 05:11 FelixErnst

@xiayh17 pls update the geom_tree() man file accordingly.

GuangchuangYu avatar Nov 25 '20 06:11 GuangchuangYu