YuLab-SMU / ggtree

:christmas_tree:Visualization and annotation of phylogenetic trees
https://yulab-smu.top/treedata-book/
821 stars 172 forks source link

Expose position argument for `geom_range()` #611

Closed willgearty closed 3 months ago

willgearty commented 3 months ago

This exposes the position argument for geom_range() so you can do something like the following:

library(ggplot2)
library(ggtree)
library(treeio)
library(deeptime)

file <- system.file("extdata/BEAST", "beast_mcc.tree", package="treeio")
beast <- read.beast(file)

ggtree(beast, position = position_nudge(x = -500))  +
  geom_range(range='length_0.95_HPD', color='red', alpha=.6, size=2,
                  position = position_nudge(x = -500)) +
  scale_x_continuous(breaks = seq(-500, -460, 10), labels = abs(seq(-500, -460, 10))) +
  theme_tree2() +
  coord_geo(pos = list("bottom", "bottom"), dat = list("stages", "periods"),
            neg = TRUE, ylim = c(0, NA), center_end_labels = TRUE, abbrv = list(TRUE, FALSE))

image

This is particularly useful for plotting trees that are made up of entirely extinct taxa which you need to bump backwards in time (since ggtree puts the root at 0).