Skip to content

geom_taxalink error "as_string() Can't convert NULL to a string." #615

Open
@ammaraziz

Description

@ammaraziz

Prerequisites

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

Describe you issue

From the ggtree book example here:

library(ggtree)
library(treeio)

treetext = "(((ADH2:0.1[&&NHX:S=human], ADH1:0.11[&&NHX:S=human]):
0.05 [&&NHX:S=primates:D=Y:B=100],ADHY:
0.1[&&NHX:S=nematode],ADHX:0.12 [&&NHX:S=insect]):
0.1[&&NHX:S=metazoa:D=N],(ADH4:0.09[&&NHX:S=yeast],
ADH3:0.13[&&NHX:S=yeast], ADH2:0.12[&&NHX:S=yeast],
ADH1:0.11[&&NHX:S=yeast]):0.1[&&NHX:S=Fungi])[&&NHX:D=N];"

tree <- read.nhx(textConnection(treetext))
ggtree(tree) + geom_tiplab() + geom_taxalink(taxa1='A', taxa2='E')

Produces this error:

Error in `as_string()`:
! Can't convert `NULL` to a string.
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace()
<error/rlang_error>
Error in `as_string()`:
! Can't convert `NULL` to a string.
---
Backtrace:
    ▆
 1. └─ggplot2:::`+.gg`(...)
 2.   └─ggplot2:::add_ggplot(e1, e2, e2name)
 3.     ├─ggplot2::ggplot_add(object, p, objectname)
 4.     └─ggtree:::ggplot_add.taxalink(object, p, objectname)
 5.       ├─base::as.vector(object$data[[as_name(object$mapping$taxa1)]])
 6.       └─rlang::as_name(object$mapping$taxa1)
 7.         └─rlang::as_string(x)
Run rlang::last_trace(drop = FALSE) to see 2 hidden frames.

I have also tried using mapping:

dat <- data.frame(from=c("A", "F", "L"), 
                  to=c("E", "K", "M"), 
                  h=c(1, 1, 0.1), 
                  type=c("t1", "t2", "t3"), 
                  s=c(2, 1, 2))
p4 <- ggtree(tree, layout="inward_circular", xlim=c(150, 0)) +
    geom_taxalink(data=dat, 
                  mapping=aes(taxa1=from, 
                              taxa2=to, 
                              color=type, 
                              size=s), 
                  ncp=10,
                  offset=0.15) + 
    geom_tiplab(hjust=1) +
    scale_size_continuous(range=c(1,3))

Error:

Error in `ggplot_add()`:
! The taxa: A, F, L, E, K, M can not be found.

Newly installed R4.4 and latest ggtree.

Software Versions

> sessionInfo()
R version 4.4.0 (2024-04-24)
Platform: aarch64-apple-darwin20
Running under: macOS Ventura 13.5

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: X
tzcode source: internal

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

other attached packages:
[1] treeio_1.28.0 ggtree_3.12.0

loaded via a namespace (and not attached):
 [1] jsonlite_1.8.8     gtable_0.3.5       crayon_1.5.2       dplyr_1.1.4       
 [5] compiler_4.4.0     tidyselect_1.2.1   Rcpp_1.0.12        aplot_0.2.2       
 [9] gridGraphics_0.5-1 parallel_4.4.0     ggplotify_0.1.2    tidyr_1.3.1       
[13] ggfun_0.1.4        scales_1.3.0       fastmap_1.2.0      lattice_0.22-6    
[17] ggplot2_3.5.1      R6_2.5.1           patchwork_1.2.0    generics_0.1.3    
[21] tidytree_0.4.6     yulab.utils_0.1.4  tibble_3.2.1       munsell_0.5.1     
[25] pillar_1.9.0       rlang_1.1.3        utf8_1.2.4         cachem_1.1.0      
[29] fs_1.6.4           lazyeval_0.2.2     memoise_2.0.1      cli_3.6.2         
[33] magrittr_2.0.3     digest_0.6.35      grid_4.4.0         lifecycle_1.0.4   
[37] nlme_3.1-164       vctrs_0.6.5        glue_1.7.0         ape_5.8           
[41] fansi_1.0.6        colorspace_2.1-0   purrr_1.0.2        tools_4.4.0       
[45] pkgconfig_2.0.3   

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions