Legend Grouped Annotation Plotly


I have a markdown document in which I use plotly to generate line plots in a report.
As I have multiple samples and 2 groups I only want the legend to hgihlight the groups
“Index” but without loosing the “Sample” names when pointing on the lines in the plot.


This is the code I have used so far:

plot_ly(data = data, x =~Coverage, y=~value, color =~Index, name =~Sample,
mode = “lines”) %>%
layout(yaxis=list(title=“Fraction”), xaxis=list(title=“Coverage”),
autosize=T, showlegend=T, title=“Report” )

So I want to get rid off the long legend and instead I prefer a small legend where only two groups “Index” (Y/N) are shown but dont want to loose the “Sample” names when pointing on the lines.

I have attached the data and a screenshot of the plot. Appreciate your help very much. Best, Peter


Just found the solution. By adding “hoverinfo” I could get the lines in the plot correctly annotatedt.