`colors` argument to `add_trace` is ignored
未关闭
还没有人认领这个 Issue。
- 主要语言
- R
- 星标
- 2.7k
- 派生
- 641
- PR 合并指标
- 30 天内没有已合并 PR
描述
This code
library(plotly)
x <- seq(1, 10)
y <- x ^ 1.5
color <- c("a", "b", "c", "d", "e",
"f", "g", "h", "i", "j")
plot_ly(type = "scatter", mode = "markers",
x = x, y = y,
color = color,
colors = "Dark2",
mode = "markers")
works as expected and produces the following plot:

This one:
library(plotly)
x <- seq(1, 10)
y <- x ^ 1.5
color <- c("a", "b", "c", "d", "e",
"f", "g", "h", "i", "j")
plt <- plot_ly(type = "scatter", mode = "markers")
plt <- add_trace(plt, x = x, y = y,
color = color,
colors = "Dark2",
mode = "markers")
plt
generates the warning
Warning messages:
1: In RColorBrewer::brewer.pal(N, "Set2") :
n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
2: In RColorBrewer::brewer.pal(N, "Set2") :
n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
and produces the following plot:

The colors argument is ignored.
The same happens when specifying a custom colour palette with colorRampPalette from RColorBrewer:
library(RColorBrewer)
library(plotly)
x <- seq(1, 10)
y <- x ^ 1.5
color <- c("a", "b", "c", "d", "e",
"f", "g", "h", "i", "j")
colors <- colorRampPalette(brewer.pal(8, "Dark2"))(10)
plt <- plot_ly(type = "scatter", mode = "markers")
plt <- add_trace(plt, x = x, y = y,
color = color,
colors = colors,
mode = "markers")
plt
As far as I can see, this makes it impossible to programmatically build a plot with add_trace and also choose the colour palette at the same time.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先复现 issue 中的两个 plot_ly 和 add_trace 示例,然后跟踪入口点 add_trace 如何处理 color 和 colors。当 add_trace 同时支持命名调色板和自定义的 colorRampPalette 输出,且不再出现报告中的调色板警告时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- r
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100