Skip to content

Manually modifying or providing dates on axis (themetree2) #665

@BaylorSci

Description

@BaylorSci

Is there a way to manually provide the dates to be used in theme_tree2? Specifically, i am interested in writing the dates between 1-11th in increments of two days.

I have two samples, taken at two different times. Despite using mrsd and setting the final sampled date (April 11th), the tree does not line up with the date line , nor does the dates presented encompass the sampled timeframe. With these files, i am able to successfully visualize this on nextstrain, but i want higher quality figures. I have tried modifying scale_x_ggtree, and various other options, but only got errors (presuming similar commands to ggplot options)

ggtree(tree, mrsd=sampling_dates[2]) + geom_tippoint(color="darkorchid",size=4, shape=18)+ geom_tiplab(size=6, as_ylab=FALSE, linesize=3,fontface=2, hjust=-0.01)+ geom_nodelab(size = 1.5, na.rm = TRUE, nudge_x = 0.045) + geom_nodepoint(color="goldenrod", size=4, alpha=1/2) + theme_tree2(bgcolor = "white")+ coord_cartesian(clip = 'off')+ xlab("Sampling period (April 2025)")+ myTheme

If i force dates (which the sampling dates as date format anyway) with as.Date=TRUE in ggtree(), i get image 2, which weirdly lengthens the branch length.

Image Image

`
version 4.4.1 (2024-06-14 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 26100)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8

time zone: America/New_York
tzcode source: internal

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

other attached packages:
[1] cowplot_1.2.0 ggplot2_4.0.0 dplyr_1.1.4 ape_5.8-1 ggtree_3.12.0

loaded via a namespace (and not attached):
[1] jsonlite_2.0.0 gtable_0.3.6 crayon_1.5.3 compiler_4.4.1 tidyselect_1.2.1
[6] Rcpp_1.1.0 aplot_0.2.9 gridGraphics_0.5-1 parallel_4.4.1 ggplotify_0.1.2
[11] tidyr_1.3.1 ggfun_0.2.0 scales_1.4.0 lattice_0.22-6 R6_2.6.1
[16] tcltk_4.4.1 labeling_0.4.3 patchwork_1.3.2 generics_0.1.4 tidytree_0.4.6
[21] yulab.utils_0.2.1 tibble_3.2.1 pillar_1.11.1 RColorBrewer_1.1-3 treeio_1.28.0
[26] rlang_1.1.5 fs_1.6.6 S7_0.2.0 lazyeval_0.2.2 cli_3.6.4
[31] withr_3.0.2 magrittr_2.0.3 digest_0.6.37 grid_4.4.1 rstudioapi_0.17.1
[36] rappdirs_0.3.3 lifecycle_1.0.4 nlme_3.1-164 vctrs_0.6.5 glue_1.8.0
[41] farver_2.1.2 sessioninfo_1.2.3 purrr_1.1.0 tools_4.4.1 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