`colors` argument to `add_trace` is ignored
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- R
- Star
- 2.7k
- Fork
- 641
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện hai ví dụ plot_ly và add_trace trong issue, sau đó theo dõi cách entry point add_trace xử lý color và colors. Hoàn thành khi add_trace hỗ trợ cả palette được đặt tên và output tùy chỉnh của colorRampPalette mà không xuất hiện cảnh báo palette đã được báo cáo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- r
- Lĩnh vực
- data-visualization
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100