liamrevell / phytools

GNU General Public License v3.0
198 stars 56 forks source link

Bug: phytools::plotTree.boxplot -- argument "x" is missing, with no default #152

Closed stiatragul closed 3 weeks ago

stiatragul commented 3 months ago

Hey Liam,

I wanted to report a potential bug I found when using the latest version of phytools (2.1-1) This is when I was trying to use phytools::plotTree.boxplot() with my own dataset.

> phytools::plotTree.boxplot(tree, xe~spp)
Error in boxplot.default(formula = list(A = list(), B = list(), C = list(),  : 
  argument "x" is missing, with no default

Reproducible example

set.seed(123)

# Generate random tree with tips A-Z
tree <- rtree(26)
tree$tip.label <- LETTERS[1:26]

# Function to generate random data for each species
generate_species_data <- function(tree, n_points_per_species = 5) {
  species_data <- list()
  for (i in 1:Ntip(tree)) {
    mean_val <- runif(1, min = 1, max = 10)  # Random mean between 1 and 10
    sd_val <- runif(1, min = 0.5, max = 2)   # Random standard deviation between 0.5 and 2
    species_data[[i]] <- rnorm(n_points_per_species, mean = mean_val, sd = sd_val)
  }
  return(species_data)
}

# Generate data for each tip
species_data <- generate_species_data(tree)

# Create data frame
species_df <- data.frame(Species = rep(tree$tip.label, each = 5), Value = unlist(species_data))

# Trait value
xe <- setNames(species_df$Value, species_df$Species)

spp <- factor(names(xe),untangle(ladderize(tree),"read.tree")$tip.label)

Tree: image

Session info:

> sessionInfo()
R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

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

other attached packages:
 [1] dplyr_1.1.3     emmeans_1.8.9   phylolm_2.6.2   geomorph_4.0.6  Matrix_1.6-1.1  rgl_1.2.1       RRPP_1.4.0      geiger_2.0.11  
 [9] phytools_2.1-1  maps_3.4.1      ape_5.7-1       ggplot2_3.4.4  

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.0        subplex_1.8             viridisLite_0.4.2       farver_2.1.1            viridis_0.6.4          
 [6] optimParallel_1.0-2     fastmap_1.1.1           combinat_0.0-8          TH.data_1.1-2           digest_0.6.33          
[11] estimability_1.4.1      lifecycle_1.0.4         survival_3.5-7          magrittr_2.0.3          compiler_4.3.1         
[16] rlang_1.1.1             tools_4.3.1             igraph_1.5.1            plotrix_3.8-2           utf8_1.2.4             
[21] yaml_2.3.7              knitr_1.45              phangorn_2.11.1         clusterGeneration_1.3.8 labeling_0.4.3         
[26] htmlwidgets_1.6.2       mnormt_2.1.1            scatterplot3d_0.3-44    multcomp_1.4-25         expm_0.999-7           
[31] withr_2.5.2             numDeriv_2016.8-1.1     grid_4.3.1              fansi_1.0.5             xtable_1.8-4           
[36] colorspace_2.1-0        future_1.33.0           globals_0.16.2          scales_1.3.0            iterators_1.0.14       
[41] MASS_7.3-60             cli_3.6.1               mvtnorm_1.2-3           rmarkdown_2.25          generics_0.1.3         
[46] rstudioapi_0.15.0       future.apply_1.11.0     splines_4.3.1           parallel_4.3.1          base64enc_0.1-3        
[51] vctrs_0.6.4             sandwich_3.0-2          jsonlite_1.8.7          listenv_0.9.0           jpeg_0.1-10            
[56] foreach_1.5.2           glue_1.6.2              parallelly_1.36.0       codetools_0.2-19        gtable_0.3.4           
[61] quadprog_1.5-8          munsell_0.5.0           tibble_3.2.1            pillar_1.9.0            htmltools_0.5.6.1      
[66] deSolve_1.38            R6_2.5.1                doParallel_1.0.17       evaluate_0.23           lattice_0.21-8         
[71] Rcpp_1.0.11             fastmatch_1.1-4         coda_0.19-4             gridExtra_2.3           nlme_3.1-163           
[76] mgcv_1.9-0              xfun_0.40               zoo_1.8-12              pkgconfig_2.0.3        

For the moment I reverted to using the version in: http://blog.phytools.org/2016/07/update-to-plottreeboxplot-for-formula_25.html.

Thanks for your attention!

liamrevell commented 3 weeks ago

Should be fixed now. Will push shortly.