title: Manipulating legend text in R plotly
body: <p>I have a <code>data.frame</code> I'd like to scatter plot using <code>R</code>'s <code>plotly</code> with two factors which I'd like to color and shape by.</p>
  
  <p>Here's my data:</p>
  
  <pre><code>set.seed(1)
  df &lt;- data.frame(x=rnorm(12),y=rnorm(12),
                   group=c(rep(1,3),rep(2,3),rep(3,3),rep(4,3)),
                   treatment=c(rep("A",6),rep("B",6)),
                   stringsAsFactors=F)
  
  df$group &lt;- factor(df$group,levels=1:4)
  df$treatment &lt;- factor(df$treatment,levels=c("A","B"))
  </code></pre>
  
  <p>Here's how I'm trying to plot:</p>
  
  <pre><code>require(plotly)
  
  plot_ly(marker=list(size=10),type='scatter',mode="markers",x=~df$x,y=~df$y,color=~df$group,symbol=~df$treatment) %&gt;% 
    add_annotations(text="group,treatment",xref="paper",yref="paper",x=1.02, xanchor="left",y=1.02,yanchor="top",legendtitle=TRUE,showarrow=FALSE) %&gt;%
    layout(xaxis=list(title="x"),yaxis=list(title="y"))
  </code></pre>
  
  <p>which gives me:
  <a href="https://i.stack.imgur.com/EsjHH.png" rel="noreferrer"><img src="https://i.stack.imgur.com/EsjHH.png" alt="enter image description here"></a></p>
  
  <p>Is it possible to get the text of <code>group</code> and <code>treatment</code> in the legend be separated by comma instead of the new line as it is now? </p>
  
  <p>This means that instead of:</p>
  
  <p>1</p>
  
  <p>A</p>
  
  <p>2</p>
  
  <p>A</p>
  
  <p>3</p>
  
  <p>B</p>
  
  <p>4</p>
  
  <p>B</p>
  
  <p>I'll have:</p>
  
  <p>1,A</p>
  
  <p>2,A</p>
  
  <p>3,B</p>
  
  <p>4,B</p>