2
votes

I am trying to specify the color of the points in my scatter plot. I would like to be able to specify a different color and alpha for each point.

The following snippet gives me the error "Error in grDevices::col2rgb(colors, alpha = alpha) : invalid color name 'rgba(105,100,30,.6)'"

I am quite stuck on this, any help is appreciated.

Thanks!

library(plotly)
library(ggplot2)
library(igraph)

tree <- make_tree(127,2)
tree_layout <- layout_as_tree(tree)
tree_layout_df <- as.data.frame(tree_layout)
Xn <- tree_layout_df[,1]
Yn <- tree_layout_df[,2]

marker_color <- rep('rgba(105,100,30,.6)',127)

reg_tree_plot <- plot_ly() %>%
    add_trace(x=~Xn, y=~Yn, type='scatter', mode='markers',color=~Xn,
              colors=marker_color)
1

1 Answers

0
votes

Following definition of marker_color is accepted in grDevices. I used runif and replicate to generate 127 (hopefully) different colours.

marker_color <- replicate(127, rgb(runif(1,0,1),runif(1,0,1),runif(1,0,1),runif(1,0,1)) )