在plotly()中的色阶

问题描述 投票:2回答:1

我想创造plotly条形图与颜色鲜明。我已经找到了如何通过变量调整颜色缩放,但不知道如何选择另一个托盘。我想用RBrewerPallet为例。这是一个例子。

library(plotly)
library(dplyr)
airquality %>% group_by(Month) %>% summarise(total = sum(Wind)) %>%
plot_ly(x = ~Month,
        y = ~total, 
        type = 'bar',
        marker = list(
          color = ~total
        ))
r colors plotly colorbrewer
1个回答
2
投票

这是一种在曲线图中指定条形图的颜色比例的方法:

  library(plotly)
  library(dplyr)
  airquality %>% group_by(Month) %>% summarise(total = sum(Wind)) %>%
    plot_ly(x = ~Month,
            y = ~total, 
            type = 'bar',
            marker = list(
              color = ~total,
              colorscale='Blues'
            ))

enter image description here

我知道这些调色板:“Blackbody”,“Blurred”,“Blues”,“Earth”,“Electric”,“Greens”,“Greys”,“Hot”,“Jet”,“Picnic”,“Portland”, “Rainbow”,“RdBu”,“Reds”,“Viridis”,“YlGnBu”,“YlOrRd”。

如果还不够,你可以手动指定:

marker = list(color = c('rgba(204,204,204,1)', 'rgba(222,45,38,0.8)', 'rgba(204,204,204,1)', 'rgba(204,204,204,1)', 'rgba(204,204,204,1)')

© www.soinside.com 2019 - 2024. All rights reserved.