ggmsa
ggmsa copied to clipboard
Last row of facet_msa has different width characters
Hi, is there a way to make the last row of facet_msa have the same width for the characters?
het_c_prots %>% msa(method = 'ClustalOmega') %>% as('AAMultipleAlignment') %>% ggmsa(seq_name = TRUE, color='Chemistry_AA', char_width = 0.5) + facet_msa(field = 100)

This is probably caused by the axis scales being of different lengths. Afaik, ggplot has no way of explicitly setting facet scales (e.g. https://github.com/tidyverse/ggplot2/issues/187 and https://github.com/tidyverse/ggplot2/pull/2747). There are blog posts out there detailing different more or less hacky ways of fixing this. One very hacky way of doing this is adding a NA value at the final position of the last row, i.e. modifying the dataframe that is being passed to ggmsa. Locally, I did this:
width <- 60
df <- as_tibble(tidy_msa('msa.fa'))
max_pos <- df %>% select(position) %>% max()
if (max_pos %% width != 0)
tmp_name <- df[[1, 'name']]
df <- df %>% add_row(name = tmp_name, position=(max_pos %/% width + 1) * width)
I also did the plotting myself, so not at all sure if this plays nice with facet_msa, but might be worth a try?
adding a NA value at the final position of the last row
It's well worth trying, I'll try to add this method to facet_msa.
Thanks.
Possibly less hacky could be to abandon facet_wrap and use something like patchwork instead. That would mean doing the range splitting ourselves, but the tidyverse cut_width function is really good at that.