bjmt / universalmotif

Motif manipulation functions for R.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adding a legend with view_motifs

kentaloupe123 opened this issue · comments

I'm plotting multiple amino acid motifs using the view_motifs function, and it appears that the coloring is based on some amino acid properties. For example, R, H, and K are all blue and positively charged amino acids.

Is there a way to add a legend with what each color represents, similar to this plot from the ggseqlogo page (https://omarwagih.github.io/ggseqlogo/) but with the multiple aligned motifs in the view_motifs plot? It even looks like the ggseqlogo may use the same coloring scheme.
image

Actually, these colours are indeed the exact same as the ggseqlogo ones for amino acids. You can reveal the legend with view_motifs(motif) + theme(legend.position = "right"). However, you will see that this shows all the colours for the individual letters instead of grouping them as ggseqlogo does. Unfortunately there isn't a simple way to do what you want using just view_motifs(). If you are really determined, you could extract the plot data (view_motifs(motif)$data), add an extra column to represent shared chemistry between letters, insert the adjusted data back into the ggplot object, then plot it with a custom colour scale (+scale_colour_manual(values=...)).

Apologies for the lack of satisfactory answer, if I ever find time I'll consider adding this kind of option. Until then I suppose you could copy-paste the ggseqlogo legend, or extract it and plot it alongside the view_motifs() output with cowplot.