我使用plot_ly将我的数据可视化为旭日形,就像之前使用Adobe Illustrator所做的那样,但未能同样为片段着色。
这是代码(颜色代码是随机的):
library(plotly)
tab <- data.frame(
labels = c("Total", "Planerlöse", "Abgeltung", "Bund", "Kanton Thurgau", "Kanton Thurgau Netto", "Gemeinden" ),
parents = c("", "Total", "Total", "Abgeltung", "Abgeltung", "Kanton Thurgau", "Kanton Thurgau"),
values = c(100, 46,54, 23.76, 30.24, 20.26, 9.97),
colors=c("#f28f1c", "#fef4e8", "#2771b0", "#e9f1f7",
"#b5b5b5", "#787878", "#333333"),
type = 'sunburst',
branchvalues = 'total'
)
fig <- plot_ly(tab, labels = ~labels, parents = ~parents,
values = ~values, colors=colors, type = 'sunburst', branchvalues = 'total'
)
fig
感谢您的建议和帮助!
您可以使用
layout
添加
colorway
将颜色添加到旭日图中,如下所示:
library(plotly)
library(dplyr)
fig <- plot_ly(tab, labels = ~labels, parents = ~parents,
values = ~values, type = 'sunburst', branchvalues = 'total'
) %>% layout(colorway = ~colors)
fig
创建于 2023-08-07,使用 reprex v2.0.2