From fa8fd3b875e1582b1024eb92a26fbf1b9b37d73c Mon Sep 17 00:00:00 2001 From: Carl Suster Date: Thu, 16 May 2024 10:00:42 +1000 Subject: [PATCH] Fix errors when all bootstrap values are filtered out https://github.com/thomasp85/ggraph/issues/370 --- R/plot_tree.R | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/R/plot_tree.R b/R/plot_tree.R index 1f12a54..b51e689 100644 --- a/R/plot_tree.R +++ b/R/plot_tree.R @@ -40,14 +40,15 @@ plot_tree <- function(phylepic, label = .data$name, bootstrap = TRUE) { if (bootstrap && (".phylepic.bootstrap_numeric" %in% colnames(tr_layout))) { p <- p + ggraph::geom_edge_elbow( - aes( - filter = ( - (!.data$node2.leaf) & - (length >= 0.05 * max(length)) & + aes(label = round(.data$node2..phylepic.bootstrap_numeric, digits = 0)), + data = function(layout) { + ggraph::get_edges()(layout) |> + dplyr::filter( + (!.data$node2.leaf), + (length >= 0.05 * max(length)), round(.data$node2..phylepic.bootstrap_numeric, digits = 0) > 0 - ), - label = round(.data$node2..phylepic.bootstrap_numeric, digits = 0) - ), + ) + }, flipped = TRUE, label_pos = 0.75, label_size = 3,