这是我现在的饼图:
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/