R Plotly - 散点图:着色各个点

时间:2017-05-30 16:16:44

标签: r ggplot2 plotly

我正在尝试指定散点图中点的颜色。我希望能够为每个点指定不同的颜色和alpha。

以下代码段给出了错误" grDevices :: col2rgb中的错误(颜色,alpha = alpha):   无效的颜色名称' 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)
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分: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)) )
相关问题