app$vspace error in building phylogenetic tree in R

469 views Asked by At

I am working with phylogenetic trees. Import the phylogenetic tree file with ggtree::read.tree and get the information with readxl::read_xlsx. I want to visualize in tree. When I try to add color and shape information (from xlsx, I tried assigning it to a variable before but it didn't work) with the ggtree::geom_tippoint function, I get the "Error in app$vspace(new_style$margin-top %||% 0) :attempt to apply non-function" error.

sessionInfo()
#> R version 4.1.1 (2021-08-10)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19044)
#> 
#> Matrix products: default
#> 
#> locale:
#> [1] LC_COLLATE=Turkish_Turkey.1254  LC_CTYPE=Turkish_Turkey.1254   
#> [3] LC_MONETARY=Turkish_Turkey.1254 LC_NUMERIC=C                   
#> [5] LC_TIME=Turkish_Turkey.1254    
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> loaded via a namespace (and not attached):
#>  [1] rstudioapi_0.13   knitr_1.36        magrittr_2.0.1    R.cache_0.15.0   
#>  [5] rlang_1.0.1       fastmap_1.1.0     fansi_0.5.0       stringr_1.4.0    
#>  [9] styler_1.6.2      highr_0.9         tools_4.1.1       xfun_0.26        
#> [13] R.oo_1.24.0       utf8_1.2.2        cli_3.2.0         withr_2.4.3      
#> [17] htmltools_0.5.2   ellipsis_0.3.2    yaml_2.2.1        digest_0.6.28    
#> [21] tibble_3.1.5      lifecycle_1.0.1   crayon_1.5.0      purrr_0.3.4      
#> [25] R.utils_2.11.0    vctrs_0.3.8       fs_1.5.0          glue_1.4.2       
#> [29] evaluate_0.14     rmarkdown_2.11    reprex_2.0.1      stringi_1.7.5    
#> [33] compiler_4.1.1    pillar_1.7.0      R.methodsS3_1.8.1 backports_1.4.1  
#> [37] pkgconfig_2.0.3

The contents of the nwk file are as follows.

  (((((((A:4,B:4):6,C:5):8,D:6):3,E:21):10,((F:4,G:12):14,H:8):13):13,((I:5,J:2):30,(K:11,L:11):2):17):4,M:56);

xlsx file content is as follows.

label con host rb color shape
A Japan Sol Tsw #ee4444 15
B Japan Sol Sw5 #ee4444 15
C South Korea Sol Tsw #ee4444 15
D South Korea Cap #A1CD42 16
E China Sol Tsw #ee4444 15
F Italy Cap Tsw #A1CD42 15
G USA Cap #A1CD42 16
H USA Per Sw5 #86d4ea 15
K Italy Sol Sw5 #ee4444 15
L Italy Cap #A1CD42 16
M Turkey Per Tsw #86d4ea 15
J Turkey Sol #ee4444 16
I Turkey Cap Sw5 #A1CD42 15
d1<- read.tree(file = "D:/Download/tree_newick.nwk")
d1a<-data.frame(read_xlsx(path="D:/Download/tree_newichk_info.xlsx", sheet = "Sheet1"))

d2<-ggtree(d1, layout = "circular")+xlim(-5, NA) %<+% d1a 

d3<-d2+geom_text(aes(label=node), hjust=.3)+
  geom_tiplab(aes(,color=d1a$con , label=label,size=10))+
  geom_tippoint(aes(shape=ifelse(rb==c("Tsw","Sw5"),15, ifelse (rb!=c("Tsw","Sw5"), 16,17))), color= ifelse(d1a$host == "Cap",'#A1CD42', ifelse (d1a$host== "Sol", '#ee4444','#86d4ea')))
d3
    
shape_f<-ifelse(d1a$rb==c("Tsw","Sw5"),15, ifelse (d1a$rb!=c("Tsw","Sw5"), 16,17))
color_f=ifelse(d1a$host == "Cap",'#A1CD42', ifelse (d1a$host== "Sol", '#ee4444','#86d4ea'))
    d4<-d2+geom_text(aes(label=node), hjust=.3)+geom_tiplab(aes(label=label))+geom_tippoint(aes(shape=shape_f,color=color_f))
d4

shape_d<-d1a$shape 
color_d<-d1a$color
    d5<-d2+ geom_text(aes(label=node), hjust=.3)+geom_tiplab(aes(label=label))+geom_tippoint(aes(shape=shape_d,color=color_d))
d5

sessionInfo()

R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=Turkish_Turkey.1254  LC_CTYPE=Turkish_Turkey.1254    LC_MONETARY=Turkish_Turkey.1254 LC_NUMERIC=C                   
[5] LC_TIME=Turkish_Turkey.1254    

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

other attached packages:
 [1] reprex_2.0.1        shiny_1.7.1         forcats_0.5.1       stringr_1.4.0       purrr_0.3.4         readr_2.0.2        
 [7] tidyr_1.1.4         tibble_3.1.5        tidyverse_1.3.1     readxl_1.3.1        ggnewscale_0.4.6    ggtreeExtra_1.2.3  
[13] ggtree_3.0.4        treeio_1.16.2       tidytree_0.3.8      ggplot2_3.3.5       dplyr_1.0.7         ape_5.6-1          
[19] treedataverse_0.0.1 BiocManager_1.30.16

loaded via a namespace (and not attached):
 [1] nlme_3.1-152       fs_1.5.0           lubridate_1.8.0    httr_1.4.2         R.cache_0.15.0     tools_4.1.1        backports_1.4.1   
 [8] bslib_0.3.1        utf8_1.2.2         R6_2.5.1           DBI_1.1.1          lazyeval_0.2.2     colorspace_2.0-3   withr_2.4.3       
[15] processx_3.5.2     tidyselect_1.1.2   compiler_4.1.1     cli_3.2.0          rvest_1.0.2        xml2_1.3.2         labeling_0.4.2    
[22] sass_0.4.0         scales_1.1.1       callr_3.7.0        digest_0.6.28      yulab.utils_0.0.4  R.utils_2.11.0     rmarkdown_2.11    
[29] pkgconfig_2.0.3    htmltools_0.5.2    styler_1.6.2       highr_0.9          dbplyr_2.1.1       fastmap_1.1.0      rlang_1.0.1       
[36] rstudioapi_0.13    gridGraphics_0.5-1 jquerylib_0.1.4    farver_2.1.0       generics_0.1.2     jsonlite_1.7.2     R.oo_1.24.0       
[43] magrittr_2.0.1     ggplotify_0.1.0    patchwork_1.1.1    Rcpp_1.0.8         munsell_0.5.0      fansi_0.5.0        clipr_0.7.1       
[50] R.methodsS3_1.8.1  lifecycle_1.0.1    stringi_1.7.5      yaml_2.2.1         grid_4.1.1         parallel_4.1.1     promises_1.2.0.1  
[57] crayon_1.5.0       miniUI_0.1.1.1     lattice_0.20-44    haven_2.4.3        hms_1.1.1          ps_1.6.0           knitr_1.36        
[64] pillar_1.7.0       glue_1.4.2         evaluate_0.14      ggfun_0.0.5        modelr_0.1.8       vctrs_0.3.8        tzdb_0.1.2        
[71] httpuv_1.6.3       cellranger_1.1.0   gtable_0.3.0       assertthat_0.2.1   cachem_1.0.6       xfun_0.26          mime_0.12         
[78] xtable_1.8-4       broom_0.7.9        later_1.3.0        aplot_0.1.3        ellipsis_0.3.2 
0

There are 0 answers