Reputation: 841
I have LiDAR dataset on which I've extracted RGB-NIR colors from a raster. I'm having no issues generating the 3d plots in plotly I want to make, or coloring the plot based on a 1-d column of values (such as NDVI); but I'm interested in coloring the points based on an RGB hex code I've written into one of the columns (taken from the raster), but i can't seem to find a way to write this in as a colorspace. While I can call on individual hex codes, it treats them as factors rather than a color specification. What I've figured out that I can do is either a) specify a qualitative color, or b) apply a color ramp. I can't seem to find a way to apply an RGB colorspace to the data.
Is there a way to specify a column in a data.frame (working in R) which has a hex or RGB code associated with each individual point in a plotly scatter plot? Is my only alternative to make a 3 color (R-G-B) color ramp, and map colors to it? Is there any way to get RGB colors to a plotly marker?
stack.exa<-data.frame(X= c(470219.59,470203.74,470215.49,470218.41,470214.88),
Y= c(5013443.99,5013439.34,5013432.39,5013437.72,5013436.6),
Z= c(645.62,629.83,638.78,617.32,639.54),
R= c(49,88,69,68,64),
B= c(76,134,102,97,96),
G= c(69,91,78,75,79),
HEX=c("#314545","#585B5B","#454E4E","#444B4B","#404F4F"))
trace.test<-plot_ly(stack.exa,
x = ~X, y = ~Y, z = ~Z,
color=~HEX,
marker=list(
size = 20,
line = list(color = 'rgba(0, 0, 0, 0)',
width = 0)
)
)
Upvotes: 1
Views: 1415
Reputation: 2431
According to ?plot_ly()
:
color (...) To avoid scaling, wrap with I()
Modifying your code to color =~ I(HEX)
seems to work. It's hard for me to tell, though, since all of the colors appear to be very similar to one another (Five Shades of Grey...)
Upvotes: 2