YuLab-SMU / ggtree

:christmas_tree:Visualization and annotation of phylogenetic trees
https://yulab-smu.top/contribution-tree-data/
838 stars 173 forks source link

Aligning tip labels in geom_tiplab results in error #540

Closed egonozer closed 1 year ago

egonozer commented 1 year ago

I have a new problem with ggtree that occurred when I updated some packages. I tired updating R and ggtree to get rid of the error, but it is consistent now. Whenever I try to use geom_tiplab() and align the labels (align=T) I end up with an error.

Here is a reproducible example:

library(ggtree)
library(ape)
set.seed(5)
tr <- rtree(10)
ggtree(tr) + geom_tiplab()

The above code works and produces a tree with tip labels

ggtree(tr) + geom_tiplab(align=T)

The above code produces the following error:

Error in `geom_segment2()`:
! Problem while converting geom to grob.
ℹ Error occurred in the 3rd layer.
Caused by error in `check.length()`:
! 'gpar' element 'lwd' must not be length 0

If I set linetype = NULL, the tree is produced with aligned labels, but without any connecting lines. If I try to set any other linetype, like "dotted" or "dashed", the error above is reproduced.

Here is my session info:

R version 4.2.2 (2022-10-31)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur ... 10.16

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/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] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] ape_5.6-2    ggtree_3.6.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9         magrittr_2.0.3     tidyselect_1.2.0   aplot_0.1.8
 [5] munsell_0.5.0      colorspace_2.0-3   lattice_0.20-45    R6_2.5.1
 [9] rlang_1.0.6        fansi_1.0.3        dplyr_1.0.10       patchwork_1.1.2
[13] parallel_4.2.2     grid_4.2.2         gtable_0.3.1       nlme_3.1-160
[17] utf8_1.2.2         ggplotify_0.1.0    cli_3.4.1          withr_2.5.0
[21] gridGraphics_0.5-1 lazyeval_0.2.2     tibble_3.1.8       lifecycle_1.0.3
[25] treeio_1.22.0      farver_2.1.1       purrr_0.3.5        tidyr_1.2.1
[29] ggplot2_3.4.0      yulab.utils_0.0.5  vctrs_0.5.0        tidytree_0.4.1
[33] glue_1.6.2         ggfun_0.0.7        labeling_0.4.2     compiler_4.2.2
[37] pillar_1.8.1       generics_0.1.3     scales_1.2.1       jsonlite_1.8.3
[41] pkgconfig_2.0.3

Any help would be appreciated. Thank you!

lixiang117423 commented 1 year ago

hey, I meet the same problem.

I update R and Bioconductor, it dose not still work.

GuangchuangYu commented 1 year ago

upgrade to ggtree v=3.6.1 (release) or github version should works.

cmkobel commented 1 year ago

FYI

You can install the github version with this command:

if (!requireNamespace("devtools", quietly = TRUE)) {
    install.packages("devtools")
}

devtools::install_github("YuLab-SMU/ggtree")