【问题标题】:R/Shiny: Unique Colors for Lines in PlotlyR/Shiny:Plotly 中线条的独特颜色
【发布时间】:2021-11-23 09:29:23
【问题描述】:

我正在尝试让 Plotly 为图表上创建的所有线条选择独特的颜色。目前有 5 条线路,但未来可能或多或少。我认为像line = ~list(color = c("red", "purple")), 这样的东西会起作用,但我什至无法让图表中的两条线成为不同的颜色。

代码:

fig <- plot_ly(theDataframe, x = ~start_date, y = ~score, type = 'scatter', mode = 'lines+markers',
                   marker = ~list(color="purple"),
                   line = ~list(color = c("red", "purple")),
                   source="master_results",
                   hoverinfo = 'text', 

【问题讨论】:

标签: r charts shiny plotly


【解决方案1】:

尝试使用色阶为described here 的离散颜色,使用定性颜色序列(参见列表here)。

line =list(colorscale = 'Accent')

如果您需要的颜色多于内置调色板中可用的颜色,请参阅this QA to generate a custom color palette with a large number of distinctive colors

【讨论】:

    猜你喜欢
    • 2021-09-29
    • 2021-09-19
    • 2021-04-15
    • 2014-11-17
    • 1970-01-01
    • 1970-01-01
    • 2018-10-23
    • 2021-10-25
    • 1970-01-01
    相关资源
    最近更新 更多