Here is a reproducible example to illustrate the issue.
library(tidyverse)
library(ggtree)
library(ape)
set.seed(32)
# 10 nodes, 3 groups
info <- tibble(
label = paste0("S", 1:10),
group = c(rep("A", 3), rep("B", 3), rep("C", 4)),
mean = c(rep(1, 3), rep(3, 3), rep(5, 4))
)
# group information, a list of three groups, contains node labels
group_info <- split(info$label, info$group)
# create data for clustering: matrix with 10 rows and 30 columns, each row
# contains normal distribution with the mean taken from info tibble
x <- expand_grid(i = 1:30, label = info$label) |>
left_join(info, by = "label") |>
rowwise() |>
mutate(value = rnorm(1, mean)) |>
pivot_wider(id_cols = label, names_from = i, values_from = value) |>
column_to_rownames("label")
# clustering
hc <- x |>
dist() |>
hclust()
# convert to phylo, add group information
ph <- ape::as.phylo(hc)
ph_gr <- groupOTU(ph, group_info)
ggtree(ph_gr, aes(colour = group), layout = "circular", branch.length = "none")
There are three groups, A, B and C, but there is an additional group called 0 in the resulting plot.
Prerequisites
Describe you issue
Ask in right place
Here is a reproducible example to illustrate the issue.
There are three groups, A, B and C, but there is an additional group called 0 in the resulting plot.
I tried to unroot the tree
but this does not help: