I have a ggtree plot where I'm working with three different varieties for a plant, and since I'm planning to add additional info in the circos around it, I was wondering whether there is a simple way to ensure the same varieties are close to each other in space/the plot.
Below, what the tree looks like. As you can see all varieties mixed with each other, whereas I wish to have them grouped in the four distinct categories. I tried to use group_by and group_split but couldn't attain the desired output.
CODE
library(dplyr)
library(tibble)
library(ggtree)
library(ggplot2)
library(phangorn)
library(ggtreeExtra)
library(RColorBrewer)
tree_NJ <- NJ(ibs_matrix_small)
###GGTREE PERSONALIZATION
meta_df_small$variety <- factor(meta_df_small$variety, levels=c('wt', 'lr', 'cv', 'unk'))
t1 <- ggtree(tree_NJ, branch.length='none', layout='circular') %<+% meta_df_small + geom_tippoint(aes(color=variety), size=1.5) +
scale_color_manual(values=c(brewer.pal(12, "Set3")[c(5, 1, 4)], "black"),
guide=guide_legend(keywidth=1, keyheight=0.8, ncol=2, order=1)) +
theme(legend.title=element_text(hjust=.5,face='italic'))
t1
ibs_matrix_small — 10 samples
structure(c(0, 0.0505857, 0.0440299, 0.0456033, 0.0467799, 0.0469243,
0.0499126, 0.0480139, 0.0474165, 0.0476661, 0.0505857, 0, 0.0491273,
0.0475119, 0.0481583, 0.0459553, 0.0483575, 0.0467083, 0.046498,
0.0486043, 0.0440299, 0.0491273, 0, 0.0435812, 0.0454869, 0.0480994,
0.0488441, 0.0472959, 0.0474109, 0.0485103, 0.0456033, 0.0475119,
0.0435812, 0, 0.0423738, 0.0449022, 0.0490488, 0.0436106, 0.0452121,
0.0444688, 0.0467799, 0.0481583, 0.0454869, 0.0423738, 0, 0.0405592,
0.0519895, 0.0447788, 0.0463662, 0.0478919, 0.0469243, 0.0459553,
0.0480994, 0.0449022, 0.0405592, 0, 0.0450354, 0.0442473, 0.0403124,
0.0465415, 0.0499126, 0.0483575, 0.0488441, 0.0490488, 0.0519895,
0.0450354, 0, 0.0481892, 0.0427342, 0.0488455, 0.0480139, 0.0467083,
0.0472959, 0.0436106, 0.0447788, 0.0442473, 0.0481892, 0, 0.0462259,
0.0492101, 0.0474165, 0.046498, 0.0474109, 0.0452121, 0.0463662,
0.0403124, 0.0427342, 0.0462259, 0, 0.0426052, 0.0476661, 0.0486043,
0.0485103, 0.0444688, 0.0478919, 0.0465415, 0.0488455, 0.0492101,
0.0426052, 0), dim = c(10L, 10L), dimnames = list(c("INLUP00130",
"INLUP00131", "INLUP00132", "INLUP00133", "INLUP00134", "INLUP00135",
"INLUP00136", "INLUP00137", "INLUP00138", "INLUP00139"), NULL))
meta_df_small — 10 samples
structure(list(id = c("INLUP00130", "INLUP00131", "INLUP00132",
"INLUP00133", "INLUP00134", "INLUP00135", "INLUP00136", "INLUP00137",
"INLUP00138", "INLUP00139"), variety = c("wt", "lr", "wt", "cv",
"lr", "lr", "cv", "cv", "wt", "wt"), location = c("ESP", "ESP",
"ESP", "ESP", "ESP", "ESP", "PRT", "ESP", "ESP", "ESP")), row.names = c(NA,
10L), class = "data.frame")




