Support for multiple legends
Useful when mapping multiple discrete variables to different visual aesthetics (i.e., marker.color & marker.symbol) without having to list every possible combination of levels.
Here is a ggplot2 example
qplot(data = mtcars, mpg, wt, color = factor(vs), shape = factor(am))

We had discussions a long time ago about an idea I was calling "legends 2.0" that would support this and many other use cases:
- create a syntax for describing trace legend items (with modifications) within annotations
- the legends we have today would then just be a special case of an annotation, but you could construct any arbitrary legend, or caption (symbols embedded in prose), or whatever, using this syntax.
For example, assuming the plot you've made above used one trace with variable color and symbol, its legend could be an annotation like (syntax off the top of my head... could be very different but you get the idea):
'<span style="font-size: 1.3em;">factor(vs)</span><br>' +
'&trace0{"marker.color":"red","marker.symbol":"circle"}; 0<br>' +
'&trace0{"marker.color":"green","marker.symbol":"circle"}; 1<br>' +
'<br>' +
'<span style="font-size: 1.3em;">factor(am)</span><br>' +
'&trace0{"marker.color":"black","marker.symbol":"circle"}; Automatic<br>' +
'&trace0{"marker.color":"black","marker.symbol":"triangle-up"}; Manual'
For the record, I don't know if other platforms implement a system like this but I'll note that this concept is inspired by a very similar system in Igor Pro.
Are there any concrete plans to support multiple legends in the near future?
Seconding this, it would be useful. On some data I'm currently working on, plotly (used in R through the corresponding package) outputs something like this:

It could be much simpler, plus it's not shown in the above picture but the factor levels are also concatenated between the two legend types being used, which is a bit ugly (it adds "()" and the spacing syntax is not correct).
I third this! It could be nice to be able to have legends specific to a give subplot rather than having to list all items in one legend.
Hopefully, this could be done also in javascript plotly!!
Has there been any progress on this?
Looking forward to have this feature available.
Is there any update on this?
This would be great for when there are multiple y axes, so that traces are more obviously linked to the relevant y axis.
This would still be really great to have for subplots and for multiple y axes.
The grouping still doesn't work as a substitute, mostly because you cannot highlight individual traces, only legend groups.
Is there any update on this? I would really like to know how to attach a legend on the right hand side of each subplot.
I was excited to see that this issue had been raised two years ago, hoping that it would be solved. Has there been any progress?
Going to add another bump to this. I'm particularly interested in the interaction with ggplotly, since currently the lack of support for multiple legends changes the plot in unexpected ways.
@alexcjohnson Can you shed a light on if giving legend groups an annotation/title is possible by now? So it basically would look like the mockup above where the legend groups have text above them.
Indeed, it would be great to have multiple legends available ! It would also solve this issue with ggplotly #1164
Is there any update. Thank you
This would be really handy. Is there an update?
Agree with @russellromney Having a separate legend option for each subplot is a high priority issue! Having one legend entry on the side or at the bottom of the subplots is not that helpful as they do not know which points are including in each subplot until they hover over the lines. See this example of how useful the individual legends would be.
What is the timeline for adding this? Thanks!
Agree.. as having legend on side with many plots confuses the user and also looks ugly.
Agree with @russellromney Having a separate legend option for each subplot is a high priority issue! Having one legend entry on the side or at the bottom of the subplots is not that helpful as they do not know which points are including in each subplot until they hover over the lines. See this example of how useful the individual legends would be.
What is the timeline for adding this? Thanks!
Very interested in this feature, so subscribing in this thread as well after the initial one here
https://github.com/ropensci/plotly/issues/1164#issuecomment-489665978
@jessicajturner this might be of interest to you too.