我使用PLOT_ly像以前使用Adobe Illustrator所做的那样,将我的数据可视化为SunBurst,但是未能同样地给数据段上色.

以下是代码( colored颜色 代码是随机的):

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

And here the original plot I'd like to replicate: enter image description here

感谢您的建议和帮助!

推荐答案

我认为这里的关键是要意识到,有些令人惊讶的是,日出图中的弧线被认为是标记,就像散点图中的点一样.这意味着我们可以按照plotly marker style docs中描述的方式设计它们的样式.例如:

# Define marker
marker <- list(
    colors = ~colors,
    line = list(
        color = "black",
        width = 2
    )
)

plot_ly(
    tab,
    labels = ~labels,
    parents = ~parents,
    values = ~values,
    type = "sunburst",
    branchvalues = "total",
    marker = marker # pass the marker here
)

enter image description here

R相关问答推荐

如何在弹性表中为类别值的背景上色

使用R中的Shapetime裁剪格栅文件

更改编号列表的 colored颜色

隐藏e_mark_line的工具提示

derrr mutate case_when grepl不能在R中正确返回值

制作等距离的线串副本

提取一个列表中单个列的重复观察结果R

仅在Facet_WRAP()中的相应方面包含geom_abline()

使用不同的定性属性定制主成分分析中点的 colored颜色 和形状

当每个变量值只能 Select 一次时,如何从数据框中 Select 两个变量的组合?

如何在PrePlot()中将多个元素设置为斜体

使用gt_summary是否有一种方法来限制每个变量集进行配对比较?

从线的交点创建面

使用&Fill&Quot;在gglot中创建 colored颜色 渐变

如何将字符类对象中的数据转换为R中的字符串

在R中使用ggraph包排列和着色圆

如何为包创建自定义roxygen2标签?

从两个数据帧中,有没有办法计算R中一列的唯一值?

以列名的字符向量作为参数按行应用自定义函数

具有某些列的唯一值的数据帧