Yes, It can be generated easily with ggtreeExtra and ggtree. You can refer to the following codes
library(ggtree) library(ggstar)
library(ggtreeExtra)
library(ggplot2)
set.seed(123)
n <- 100
tr <- rtree(n)
dat1 <- data.frame(
id=rep(tr$tip.label, 8),
sample=c(rep(c("A1","A2", "A3", "A4"), each=n),
rep(c("B1", "B2", "B3", "B4"), each=n)),
group=c(rep("A", n * 4), rep("B", n * 4)),
subgroup=rep("T", n*8)
)
dat1[sample(nrow(dat1), 700), "subgroup"] <- NA
dat1$subgroup <- ifelse(!
is.na(dat1$subgroup), dat1$group, NA)
gf1 <- geom_fruit(
data=dat1,
geom=geom_star,
mapping=aes(x=sample, y=id, color=group),
starshape=15,
pwidth=0.12
)
gf2 <- geom_fruit(
data=dat1,
geom=geom_star,
mapping=aes(x=sample, y=id, fill=subgroup),
starstroke=0,
starshape = 15,
pwidth=0.12,
axis.params = list(axis="x", text.size=1.2, vjust=1, line.size=0)
)
linecolor <- scale_color_manual(values=c("red", "blue"))
fillcolor <- scale_fill_manual(values=c("red", "blue"), na.translate = FALSE)
fg <- geom_fruit_list(gf2, gf1, linecolor, fillcolor)