gae*_*cia 1 r d3.js donut-chart sunburst-diagram htmlwidgets
我似乎无法理解如何sunburst在sunburstR包处理某些paramenters中,给它的颜色以及如何应用颜色对不同类别分别是矢量,以及如何显示标签的不同分区。
它是否有逻辑,是否有更好的方法来手动指定哪种颜色应该与哪个根/叶搭配?
来自?sunburst:(不知道他们所说的“提供具有范围和/或域的列表”是什么意思。
colors
vector of strings representing colors as hexadecimal for manual colors.
If you want precise control of colors, supply a list with range and/or domain.
For advanced customization, supply a JavaScript function.
Run Code Online (Sandbox Code Playgroud)
谢谢!
sourcestatus
# A tibble: 5 x 2
SourceStatus count
<chr> <int>
1 blood-affected 4369
2 blood-unaffected 2848
3 blood-unknown 1
4 cell_line-affected 1797
5 cell_line-unaffected 151
Run Code Online (Sandbox Code Playgroud)
创建旭日:
sunburst(sourcestatus, count = TRUE, percent= T,
colors = c("#6b5b95", "#feb236", "#d64161", "#ff7b25"))
Run Code Online (Sandbox Code Playgroud)
用颜色列表简单地指定颜色:
colors = c("#6b5b95", "#feb236", "#d64161", "#ff7b25")
Run Code Online (Sandbox Code Playgroud)
将逐层重复顺时针移动的颜色。这确保同一层中没有相邻的叶子具有相同的颜色(子/父叶子可以)。如果仅指定一种颜色,则忽略该颜色并使用默认调色板。
虽然不清楚如何使用事物的 r 侧的域和范围指定颜色,但您可以指定您希望每个叶子填充的颜色。如果你有很多叶子,你会想要构建一个函数来填充这些数据,但这里有一个使用快速和脏数据框和几种颜色的演示:
library(sunburstR)
leafs <- c("base","base-child1-grandchild1","base-child1-grandchild2","base-child1","base-child2-grandchild3","base-child2","base-child3-grandchild4","base-child3-grandchild5","base-child3-grandchild6","base-child3-grandchild7","base-child3")
values <- c(200,15,10,20,55,10,120,30,30,20,10)
# colors
colors <- c("#c994c7","#6a51a3","#807dba","#bcbddc","#74c476","#c7e9c0","#fcbba1","#fc9272","#ef3b2c","#cb181d","#99000d")
# match those colors to leaf names, matched by index
labels <- c("base","grandchild1","grandchild2","child1","child2","grandchild3","grandchild4","grandchild5","grandchild6","grandchild7","child3")
df = data.frame(v1=leafs, v2=values);
sunburst(df,
colors = list(range = colors, domain = labels))
Run Code Online (Sandbox Code Playgroud)
给每个一级孩子自己的配色方案:
输入颜色的列表包含一系列输出颜色和输入叶子名称域,允许将特定颜色与特定叶子配对。