2017-05-30 241 views
0

我想在散点图中指定点的颜色。我希望能够为每个点指定不同的颜色和字母。R Plotly - 散点图:着色各个点

下面的代码片段给我的错误 “在grDevices错误:: col2rgb(颜色,阿尔法=阿尔法): 无效的颜色名称 'RGBA(105,100,30 .6)'”

我很卡在此,任何帮助表示赞赏。

谢谢!

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)

回答

0

marker_color定义grDevices被接受。我用runifreplicate生成127(希望)不同的颜色。

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

你知道marker_color如何与plotly结合? –

+0

我现在不知道该怎么做。我认为最好关闭这个问题并用可重现的例子开创一个新问题。 – Lstat