Hi there,
I think I found a problem with aes(subset) in geom_tiplab or geom_tippoint (although it's possible I'm misunderstanding how subset works). I think older versions of ggtree didn't have this issue but I'm not sure. I am using the current release versions of all packages.
There are ways to work around this but it'd be nice not to have to do use them!
A reprex is below.
Thank you!
Janet Young
Fred Hutch Cancer Center
library(ape)
library(ggtree)
#> ggtree v4.0.5 Learn more at https://yulab-smu.top/contribution-tree-data/
#>
#> Please cite:
#>
#> S Xu, Z Dai, P Guo, X Fu, S Liu, L Zhou, W Tang, T Feng, M Chen, L
#> Zhan, T Wu, E Hu, Y Jiang, X Bo, G Yu. ggtreeExtra: Compact
#> visualization of richly annotated phylogenetic data. Molecular Biology
#> and Evolution. 2021, 38(9):4039-4042. doi: 10.1093/molbev/msab166
#>
#> Attaching package: 'ggtree'
#> The following object is masked from 'package:ape':
#>
#> rotate
library(tidytree)
#> tidytree v0.4.7 Learn more at https://yulab-smu.top/contribution-tree-data/
#>
#> Please cite:
#>
#> S Xu, Z Dai, P Guo, X Fu, S Liu, L Zhou, W Tang, T Feng, M Chen, L
#> Zhan, T Wu, E Hu, Y Jiang, X Bo, G Yu. ggtreeExtra: Compact
#> visualization of richly annotated phylogenetic data. Molecular Biology
#> and Evolution. 2021, 38(9):4039-4042. doi: 10.1093/molbev/msab166
#>
#> Attaching package: 'tidytree'
#> The following objects are masked from 'package:ape':
#>
#> drop.tip, keep.tip
#> The following object is masked from 'package:stats':
#>
#> filter
# Get example tree data, with tipdata
tr <- rtree(10)
## Make table of information about tips
tree_info <- data.frame(label = paste0("t",1:10),
group_character = c(rep("group1", 3),
rep("group2", 4),
rep("group3", 3)))
## add factor column:
tree_info[,"group_factor"] <- factor(tree_info[,"group_character"])
## add integer column:
tree_info[,"group_integer"] <- as.integer(gsub("group","",tree_info[,"group_character"]))
## add TRUE/FALSE column:
tree_info[,"in_group2"] <- tree_info[,"group_character"] == "group2"
tree_info
#> label group_character group_factor group_integer in_group2
#> 1 t1 group1 group1 1 FALSE
#> 2 t2 group1 group1 1 FALSE
#> 3 t3 group1 group1 1 FALSE
#> 4 t4 group2 group2 2 TRUE
#> 5 t5 group2 group2 2 TRUE
#> 6 t6 group2 group2 2 TRUE
#> 7 t7 group2 group2 2 TRUE
#> 8 t8 group3 group3 3 FALSE
#> 9 t9 group3 group3 3 FALSE
#> 10 t10 group3 group3 3 FALSE
## Join info and tree together:
tr_plus_info <- left_join(tr, tree_info, by="label")
#### Now plot the tree
# Plot, using `in_group2` column (TRUE/FALSE) to subset geom_tippoint - this works:
ggtree(tr_plus_info) +
geom_tiplab(aes(color=group_character), offset=0.05) +
geom_tippoint(aes(subset=in_group2,
color=group_character),
size=3,
show.legend = FALSE)

# Plot, using a logical test on the `group_integer` column (group_integer==2) to subset geom_tippoint - this works:
ggtree(tr_plus_info) +
geom_tiplab(aes(color=group_character), offset=0.05) +
geom_tippoint(aes(subset= (group_integer==2),
color=group_character),
size=3,
show.legend = FALSE)

# Plot, using a logical test on the `group_factor` column (group_factor=="group2") to subset geom_tippoint - this fails:
ggtree(tr_plus_info) +
geom_tiplab(aes(color=group_character), offset=0.05) +
geom_tippoint(aes(subset= (group_factor=="group2"),
color=group_character),
size=3,
show.legend = FALSE)
#> Error:
#> ! Problem while computing aesthetics.
#> ℹ Error occurred in the 4th layer.
#> Caused by error:
#> ! object 'group2' not found
# Same problem if we try to subset geom_tiplab instead of geom_tippoint
ggtree(tr_plus_info) +
geom_tiplab(aes(subset= (group_factor=="group2"),
color=group_character), offset=0.05) +
geom_tippoint(aes(color=group_character),
size=3,
show.legend = FALSE)
#> Error:
#> ! Problem while computing aesthetics.
#> ℹ Error occurred in the 3rd layer.
#> Caused by error:
#> ! object 'group2' not found
# Same problem using the group_character column
ggtree(tr_plus_info) +
geom_tiplab(aes(color=group_character), offset=0.05) +
geom_tippoint(aes(subset= (group_character=="group2"),
color=group_character),
size=3,
show.legend = FALSE)
#> Error:
#> ! Problem while computing aesthetics.
#> ℹ Error occurred in the 4th layer.
#> Caused by error:
#> ! object 'group2' not found
# But if I store the desired value in a variable it succeeds
group_of_interest <- "group2"
ggtree(tr_plus_info) +
geom_tiplab(aes(color=group_character), offset=0.05) +
geom_tippoint(aes(subset= (group_character==group_of_interest),
color=group_character),
size=3,
show.legend = FALSE)

### sessionInfo
sessionInfo()
#> R version 4.5.3 (2026-03-11)
#> Platform: aarch64-apple-darwin20
#> Running under: macOS Tahoe 26.4
#>
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.1
#>
#> 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: America/Los_Angeles
#> tzcode source: internal
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] tidytree_0.4.7 ggtree_4.0.5 ape_5.8-1
#>
#> loaded via a namespace (and not attached):
#> [1] yulab.utils_0.2.4 rappdirs_0.3.4 generics_0.1.4
#> [4] tidyr_1.3.2 fontLiberation_0.1.0 ggplotify_0.1.3
#> [7] lattice_0.22-9 digest_0.6.39 magrittr_2.0.4
#> [10] evaluate_1.0.5 grid_4.5.3 RColorBrewer_1.1-3
#> [13] fastmap_1.2.0 jsonlite_2.0.0 purrr_1.2.1
#> [16] aplot_0.2.9 scales_1.4.0 fontBitstreamVera_0.1.1
#> [19] lazyeval_0.2.2 cli_3.6.5 rlang_1.1.7
#> [22] fontquiver_0.2.1 reprex_2.1.1 withr_3.0.2
#> [25] yaml_2.3.12 otel_0.2.0 gdtools_0.5.0
#> [28] tools_4.5.3 parallel_4.5.3 dplyr_1.2.0
#> [31] ggplot2_4.0.2 vctrs_0.7.2 R6_2.6.1
#> [34] gridGraphics_0.5-1 lifecycle_1.0.5 htmlwidgets_1.6.4
#> [37] fs_2.0.1 ggfun_0.2.0 MASS_7.3-65
#> [40] treeio_1.34.0 pkgconfig_2.0.3 pillar_1.11.1
#> [43] gtable_0.3.6 glue_1.8.0 Rcpp_1.1.1
#> [46] systemfonts_1.3.2 xfun_0.57 tibble_3.3.1
#> [49] tidyselect_1.2.1 rstudioapi_0.18.0 ggiraph_0.9.6
#> [52] knitr_1.51 farver_2.1.2 htmltools_0.5.9
#> [55] nlme_3.1-169 patchwork_1.3.2 labeling_0.4.3
#> [58] rmarkdown_2.31 compiler_4.5.3 S7_0.2.1
Created on 2026-04-02 with reprex v2.1.1
Hi there,
I think I found a problem with aes(subset) in geom_tiplab or geom_tippoint (although it's possible I'm misunderstanding how subset works). I think older versions of ggtree didn't have this issue but I'm not sure. I am using the current release versions of all packages.
There are ways to work around this but it'd be nice not to have to do use them!
A reprex is below.
Thank you!
Janet Young
Fred Hutch Cancer Center
Created on 2026-04-02 with reprex v2.1.1