title: How can I explicitly assign unique colors to every point in an R Plotly scatterplot?
body: <p>I have some data like this:</p>
  
  <pre><code>data &lt;- data.frame(x=runif(500), y=runif(500), z=runif(500))
  </code></pre>
  
  <p>I want a scatterplot with points colored independently/discretely in each dimension (X, Y, and Z) using RGB values.</p>
  
  <p>This is what I have tried:</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>library(dplyr)
  library(plotly)
  
  xyz_colors &lt;- rgb(data$x, data$y, data$z)
  
  plot_ly(data = data, 
      x = ~x, y = ~y, z = ~z, 
      color= xyz_colors, 
      type = 'scatter3d', 
      mode='markers') %&gt;%
    layout(scene = list(xaxis = list(title = 'X'),
                        yaxis = list(title = 'Y'),
                        zaxis = list(title = 'Z')))
  </code></pre>
  
  <p><strong>Plot:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/iXoNZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iXoNZ.png" alt="enter image description here"></a></p>
  
  <p>RColorBrewer thinks I'm trying to create a continuous scale from 500 intermediate colors:</p>
  
  <pre><code>Warning messages:
  1: In RColorBrewer::brewer.pal(N, "Set2") :
    n too large, allowed maximum for palette Set2 is 8
  Returning the palette you asked for with that many colors
  
  2: In RColorBrewer::brewer.pal(N, "Set2") :
    n too large, allowed maximum for palette Set2 is 8
  Returning the palette you asked for with that many colors
  </code></pre>
  
  <p>What are some correct ways to color the points like this in R with Plotly?
  Also, how can one generally assign colors to data points in R with Plotly, individually?</p>
  
  <p>To clarify, I am trying to color each point where the color is of the format "#XXYYZZ" where 'XX' a value between 00 and FF linearly mapped to the value of data$x from 0 to 1. That is, the X dimension determines the amount of red, the Y dimension determines the amount of green, and the Z dimension determines the amount of blue. At 0,0,0 the point should be black and at 1,1,1 the point should be white. The reason for this is to make as easy to visualize the 3D position of the points as possible.</p>