YuLab-SMU / ggmsa

:traffic_light: Visualizing publication-quality multiple sequence alignment using ggplot2
http://yulab-smu.top/ggmsa
200 stars 22 forks source link

Combine ggmsa plot and ggtree? #23

Open Ekie22 opened 2 years ago

Ekie22 commented 2 years ago

Hi, I am wondering if it is possible to combine the ggmsa plot with a ggtree. I tried it with aplot, but the alignment was not ordered according to the tree tips (see below). I am using R version 4.1.2, ggtree version 3.1.4.991, ggmsa version 1.1.0 and aplot version 0.1.1.

library(Biostrings)
library(ggtree)
library(ggmsa)
library(aplot)

nt_sequences <- system.file("extdata", "LeaderRepeat_All.fa", package = "ggmsa")
nt_align <- readDNAStringSet(nt_sequences)
p <-  ggmsa(nt_align, seq_name = T, char_width = 0.5, font = NULL, color = "Chemistry_NT")
set.seed(42)
g <- ggtree(rtree(length(names(nt_align)), tip.label = names(nt_align))) + geom_tiplab() + 
  xlim(0,9)
p %>% insert_left(g, width = 0.5)

Resulting plot: ggmsa_issue

Any help or suggestion is appreciated. Thanks

GuangchuangYu commented 2 years ago

381702071

We may support it directly in a future release. Currently, you can use get_taxa_name to extract the order of tips in the tree to reorder the msa as demonstrated in the screenshot.

Ekie22 commented 2 years ago

Many thanks.