You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何下移ggtree结合deeptime绘制的系统发育树时间轴

解决半环形系统发育树时间轴与树结构重叠的问题

针对你遇到的时间轴与树根、分支重叠的情况,有以下几种直接的调整方法:

方法1:扩展X轴范围,拉开根与时间轴的距离

通过scale_x_continuous的expand参数扩展X轴左侧(对应更早的地质时间)的空间,让树根位置与时间轴刻度错开:

修改后的代码片段:

scale_x_continuous(
  breaks = seq(-800, 0, 200),
  labels = seq(800, 0, -200),
  expand = expansion(add = c(60, 0))  # 调整add的数值,越大空间越宽
)

方法2:调整Y轴下限,将时间轴向下推移

通过扩展Y轴的下限空间,把时间轴整体向下移动,避免与树的底部结构重叠:

方式A:用scale_y_continuous扩展

在代码中添加scale_y_continuous:

p <- revts(
  ggtree(TOL1, layout = "fan", open.angle = 180, size = 0.5)  +
    aes(colour = group) +
    theme_tree2() +
    geom_tippoint(size = 1.5, stroke = 0, alpha = 0.4) +
    scale_y_continuous(expand = expansion(add = c(3, 0))) +  # 向下扩展Y轴空间
    coord_geo_polar(
      dat = time,
      fill = "white",
      alpha = 0,
      lwd = 0
    ) +
    # 后续theme、scale等代码不变
    ...
)

方式B:在coord_geo_polar中手动设置Y轴范围

直接在coord_geo_polar里指定ylim参数,强制下移时间轴:

coord_geo_polar(
  dat = time,
  fill = "white",
  alpha = 0,
  lwd = 0,
  ylim = c(-4, NA)  # 负数越小,时间轴下移越多
)

方法3:调整图形底部边距

如果上述方法效果不够,可以增大plot.margin的底部边距,给时间轴留出更多空间:

theme(
  plot.margin = unit(c(1, 1, 5, 1), "mm"),  # 把第三个数值(bottom)从0改成5
  axis.text.r = element_text(size  = 2),
  legend.position = "none"
)

你可以根据实际图形的重叠程度,微调上述参数的数值,找到最适合的效果。

内容的提问来源于stack exchange,提问作者Anh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 22:32:43