r - 如何使用十六进制字符串在 plotly for r 中更改饼图中切片的颜色?

标签 r pie-chart plotly

这是我现在的饼图:

library(plotly)
library(RColorBrewer)


P <- data.frame (labels = c("A", "B", "C", "D", "E"),
             values = c(5, 8, 3, 4, 9))

plot_ly(P, labels = labels, values = values, type = "pie",
    marker = list(colors=c("lightskyblue", "deepblue", "dodgerblue", "midnightblue", "powderblue")),
    textinfo="value",
    textposition="outside") 

我想用十六进制字符串改变它的颜色,这样我就可以使用来自 RColorBrewer 的调色板。提前谢谢!

最佳答案

只需将十六进制值放入字符串中,前面加上一个井号(井号)#。十六进制的前两位代表红色,接下来的两位代表绿色,然后两位代表蓝色(#RRGGBB)。或者,您可以为 alpha(透明度)添加额外的两位数字 (#RRGGBBAA)。

例如

plot_ly(P, labels = labels, values = values, type = "pie",
    marker = list(colors=c("#556677", "#AA3344", "#772200", 
                           "#11AA22", "#AA231B88")), # the last color has alpha value set.
    textinfo="value",
    textposition="outside") 

关于r - 如何使用十六进制字符串在 plotly for r 中更改饼图中切片的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38024728/

相关文章:

R/ Shiny : Plotly reactive height discarded after window resize

python - 如何在plotly python中的所有子图中添加水平线

python - 如何去掉 Choropleth 的白色背景?

r - 在 R 中为栅格设置可覆盖的临时文件

r - 泛型函数 R 中的作用域

r - face_wrap 图与 R 中的 pROC 包(几个变量)

visualization - 如何在 google Visualization : Pie Chart 中显示所有图例

r - 后续: Write from R into template in excel while preserving formatting

java - MPAndroidChart 值没有像我提到的那样出现?

javascript - Highchart js点击旋转展开圆弧