【发布时间】:2025-12-17 11:45:01
【问题描述】:
我想自定义 plotly 图中的颜色。根据docs,这适用于连续变量和尺度:
library(plotly)
plot_ly(iris, x = Petal.Length, y = Petal.Width,
color = Sepal.Length, colors = c("#132B43", "#56B1F7"),
mode = "markers")
但是,如果我将参数设置为离散颜色(字符或因子),这仍然有效,但会引发警告:
> plot_ly(iris, x = Petal.Length, y = Petal.Width,
color = Sepal.Length>6, colors = c("#132B43", "#56B1F7"),
mode = "markers")
Warning message:
In RColorBrewer::brewer.pal(N, "Set2") :
minimal value for n is 3, returning requested palette with 3 different levels
我该如何正确地做到这一点?
【问题讨论】: