简体   繁体   English

R Plotly-散点图:为单个点着色

[英]R Plotly - Scatter plot: Colouring individual points

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. 我希望能够为每个点指定不同的颜色和Alpha。

The following snippet gives me the error "Error in grDevices::col2rgb(colors, alpha = alpha) : invalid color name 'rgba(105,100,30,.6)'" 以下代码段给我错误“ grDevices :: col2rgb(colors,alpha = alpha)中的错误:无效的颜色名称'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) 

Following definition of marker_color is accepted in grDevices . 继定义marker_color在接受grDevices I used runif and replicate to generate 127 (hopefully) different colours. 我使用了runifreplicate以生成127种(希望)不同的颜色。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM