title: plotly linetype poperty setting in R
body: <p>I am trying to set the line type("solid", "dash", "dot" etc) for multiple lines in plotly. I have a column(factor variable) in my data frame which specifies the type of line. </p>
  
  <p>Below is the sample code I am working with.</p>
  
  <pre><code>mydf &lt;- data.frame(x = c(1:10), y1 = c(11:20), y2 = c(21:30))
  mydf1 &lt;- gather(mydf,'var', 'val', -x)
  mydf1$lt &lt;- factor(c(rep("solid",10),rep("dot",10)))
  pal &lt;- RColorBrewer::brewer.pal(nlevels(mydf1$lt),"Set1")
  p &lt;-plot_ly(mydf1, x = x, y = val, type = 'line', color = var,colors = pal,line = list(width = 3, dash = lt))
  p&lt;- layout(p,title = "Hello", annotations = list(x = mydf1$x, y = mydf1$var))
  
  p   
  </code></pre>
  
  <p>mydf1$lt specifies the required line type.
  For the above example, y1 must be solid line and y2 must be dotted line.</p>
  
  <p><a href="https://i.stack.imgur.com/VqCwk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VqCwk.png" alt="enter image description here"></a></p>
  
  <p>I can solve the issue by individually adding lines using add_trace(). I am looking for a more concised, elegant way of doing the same. Below is one possible solution.</p>
  
  <pre><code>p1 &lt;- plot_ly(mydf)
  p1 &lt;- add_trace(p1, x = x, y = y1, line = list(dash = "dash"))
  p1 &lt;- add_trace(p1, x = x, y = y2, line = list(dash = "solid"))
  p1
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/CXAJD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CXAJD.png" alt="enter image description here"></a></p>