r - 条形图 R 中的颜色

标签 r plotly bar-chart color-scheme stacked-chart

另请参阅Custom colors in R Plotly

在条形图中使用变量表示颜色时。 如何更改默认配色方案?

    library(plotly)
    library(dplyr)

p <- ggplot2::diamonds %>% count(cut, clarity) %>%
  plot_ly(x = ~cut, y = ~n, color = ~clarity) %>%
  layout(barmode = "stack") 

p

enter image description here

最佳答案

plot_ly

colors 参数采用长度为类别数的向量:

p <- ggplot2::diamonds %>% count(cut, clarity) %>%
   plot_ly(x = ~cut, y = ~n, color = ~clarity, colors = rainbow(10)) %>%
   layout(barmode = "stack") 
p

关于r - 条形图 R 中的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59392874/

相关文章:

python - 如何使用plotly imshow设置xlim/ylim?

python - 无法重新采样然后绘制 Pandas 数据框

r - 在ggplotly上添加第二个Y轴

r - 绘图条形图中的颜色

jquery - 如何在kendo ui中制作左侧条形图?

python - 如何增加条形图上日期的 xticks/标签的频率?

R-XGBoost : Error building DMatrix

r - 在 R 上保存传单

mysql - RODBC 错误 : Could not SQLExecDirect in mysql

r - 是否可以在不重新创建或修改几何图层的情况下添加 ggplot 美学?