在plotly()中的色阶

时间:2018-03-26 11:41:43

标签: r colors plotly colorbrewer

我想创建带有鲜明色彩的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
        ))

1 个答案:

答案 0 :(得分:3)

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

  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"," Bluered"," Blues"," Earth"," Electric& #34;," Greens"," Grays"," Hot"," Jet"," Picnic",& #34; Portland"," Rainbow"," RdBu"," Reds"," Viridis"," YlGnBu&# 34;," 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)')