title: Legend near each plot in subplot plot_ly in R
body: <p>I use subplot function from plotly to plot two graphs (one under another) in my my R-shiny application. The legend is common for both graphs meaning that I have only one column with all legends assembled together. </p>
  
  <p>I want to have the legends near each graph separately in subplot. How can I obtain it? </p>
  
  <pre><code>p1 &lt;-
   iris%&gt;%
   group_by(Species)%&gt;%
   plot_ly(x=~Sepal.Length, color= ~Species, legendgroup=~Species)%&gt;%
   add_markers(y= ~Sepal.Width)
  p2 &lt;-
   iris%&gt;%
   group_by(Species)%&gt;%
   plot_ly(x=~Sepal.Length, color= ~Species, legendgroup=~Species)%&gt;%
   add_markers(y= ~Sepal.Width)
  
   subplot(p1,p2, nrows = 2, shareX = T, shareY = F, titleX = T, titleY = T)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/s8pdX.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s8pdX.jpg" alt="The result of the above code"></a></p>
  
  <p>And my desired layout is the following: 
  <a href="https://i.stack.imgur.com/SxDed.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SxDed.png" alt="The desired result"></a></p>