title: 3D Biplot in plotly - R
body: <p>I want to build a 3D PCA bi-plot using <code>plotly</code> package because the graph is nice and interactive in html format (something that I need).</p>
  
  <p>My difficulty is to add the loading. I want the loading to be presented as straight lines from the point <code>(0,0,0)</code> (i.e. the equivalent to 2D biplots) </p>
  
  <p>So all in all I don't know how to add straight lines starting from the centre of the 3D graph.</p>
  
  <p>I have calculated the scores and loading using the <code>PCA</code> function;</p>
  
  <pre><code>pca1 &lt;- PCA (dat1, graph = F)
  </code></pre>
  
  <p>for scores:</p>
  
  <pre><code>ind1 &lt;- pca1$ind$coord[,1:3]
  x &lt;- ind1[,1] ; y &lt;- ind1[,2] ; z &lt;- ind1[,3]
  </code></pre>
  
  <p>for loadings:</p>
  
  <pre><code>var1 &lt;- pca1$var$coord[,1:3]
  xl &lt;- var1[,1] ; yl &lt;- var1[,2] ; zl &lt;- var1[,3]
  </code></pre>
  
  <p>and using the code bellow the 3D score plot is generated;</p>
  
  <pre><code>p &lt;- plot_ly( x=x, y=y, z=z, 
   marker = list(opacity = 0.7, color=y  , colorscale = c('#FFE1A1', '#683531'), showscale = F)) %&gt;% 
    layout(title = "3D Prefmap",
           scene = list(
             xaxis = list(title = "PC 1"), 
             yaxis = list(title = "PC 2"), 
             zaxis = list(title = "PC 3")))
  </code></pre>