ggtree报错:Error in `stat_tree()`

一. 报错 在运行ggtree脚本的时候出现报错: Error in `stat_tree()`: ! Problem while converting geom to grob. ℹ Error occurred in the 1st layer. Caused by error in `is.waive()`:...

一. 报错

在运行ggtree脚本的时候出现报错:

Error in `stat_tree()`:

! Problem while converting geom to grob.

ℹ Error occurred in the 1st layer.

Caused by error in `is.waive()`:

! could not find function "is.waive"

Backtrace:

     ▆

  1. ├─base::print(p)

  2. ├─ggplot2 (local) `print.ggplot2::ggplot`(p)

  3. │ ├─ggplot2::ggplot_gtable(data)

  4. │ └─ggplot2 (local) `ggplot_gtable.ggplot2::ggplot_built`(data)

  5. │   └─ggplot2:::by_layer(...)

  6. │     ├─rlang::try_fetch(...)

  7. │     │ ├─base::tryCatch(...)

  8. │     │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)

  9. │     │ │   └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])

 10. │     │ │     └─base (local) doTryCatch(return(expr), name, parentenv, handler)

 11. │     │ └─base::withCallingHandlers(...)

 12. │     └─ggplot2 (local) f(l = layers[[i]], d = data[[i]])

 13. │       └─l$draw_geom(d, layout)

 14. │         └─ggplot2 (local) draw_geom(..., self = self)

 15. │           └─self$geom$draw_layer(...)

 16. │             └─ggplot2 (local) draw_layer(..., self = self)

 17. │               └─base::lapply(...)

 18. │                 └─ggplot2 (local) FUN(X[[i]], ...)

 19. │                   ├─rlang::inject(self$draw_panel(data, panel_params, coord, !!!params))

 20. │                   └─self$draw_panel(...)

 21. │                     └─ggtree (local) draw_panel(...)

 22. │                       └─ggplot2:::empty(data)

 23. └─base::.handleSimpleError(...)

 24.   └─rlang (local) h(simpleError(msg, call))

 25.     └─handlers[[1L]](cnd)

 26.       └─cli::cli_abort(...)

 27.         └─rlang::abort(...)

Execution halted


归根结底错误就是这个:! could not find function "is.waive"

这个是is.waive()应该是老版本得ggplot2里面的函数,版本大概是3.5.x,如果用现在比较新版本的R去进行install.package的话,下载的ggplot是4.0.2,在这个版本里面没有is.waive()得函数。

二. 解决方案

关于这个事情有几个解决的办法:
1. 降低ggplot2得版本,降低到3.5.x版本:
remotes::install_version("ggplot2", version = "3.5.1")
2. 升级ggtree到最新版本:
因为ggtree得作者就此事做出过回应,直接升级到最新版就可以了:version of ggplot2 and ggtree doesn‘t match · Issue #663 · YuLab-SMU/ggtree
remotes::install_github("YuLab-SMU/ggtree")
如果在运行这个命令得时候报错了的话,大概率是因为依赖得版本不对,这个时候可以尝试这个:
remotes::install_github("YuLab-SMU/ggtree", dependencies = TRUE, upgrade = "always")
会把依赖都升级了,但是升级的包很多,大家酌情使用吧。

3. 手动修改自己的脚本,使其能找到函数。如上面github得回答所说:
在运行 ggtree 前加一句
if (!exists("is.waive")) {
  is.waive <- \(x) inherits(x, "waiver") # nolint
}
attachments-2026-03-peT69AYb69ba51ecd6dbc.png
大家酌情使用自己觉得可行的方案。我个人比较推荐使用2
  • 发表于 1天前
  • 阅读 ( 11 )
  • 分类:R

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
Ti Amo
Ti Amo

78 篇文章

作家榜 »

  1. omicsgene 760 文章
  2. 安生水 370 文章
  3. Daitoue 167 文章
  4. 生物女学霸 120 文章
  5. xun 96 文章
  6. rzx 88 文章
  7. 红橙子 81 文章
  8. Ti Amo 78 文章