Sharing legends across two plots

Is it possible, and if it is, how do I do it, to share a single legend and colors across two different plots?

I have a set of samples, across two different data sets. Each sample has a diagnosis. I’m wanting to plot each dataset and have the same diagnoses given the same colors across both plots.

I don’t want to use a sub-plot, I want two plots that will appear in different places, but have the same legend, and the same colors associated with each category.

Feels like it should be simple, but I can’t find anything that isn’t about sharing legends across sub-plots at the moment.


Hi @tirohia1 so basically you want each category to have a specific color? Not sure what do you mean by “share legends”.

Could you add an example?

This first legend is from the RNA data from my set of samples. The category colors are currently assigned randomly, only at some point, I’ll need to figure out how to manage that, because the categories can change, i.e. Diagnosis, Final Diagnosis, …
That’s another question though I think.

This legend is from the Methylation data from the same set of samples. I need to figure out how to have the legend exactly the same as first plot for consistency. The two plots are not displayed in the same place, i.e. creating these as subplots in a single plot won’t work.


I assume your have a full list of categories. I would assign a color to each of these categories, for example using a dictionary.

Here an example: