我正在绘制一个日出甜甜圈,但我不明白为什么总数是错误的。
library(sunburstR)
reports <- data.frame(
sequence = c("SVP-VP-Dir-end","SVP-VP-Dir-end","SVP-VP-Dir-end","SVP-VP-Dir-end","SVP-No VP-Dir-end","SVP-No VP-Dir-end","SVP-No VP-Dir-end"),
freq = as.numeric(c("167","60","51","32","5","1","1")))
sunburst(reports, count = TRUE)它应该是317中的100% 317。有人知道怎么解决这个问题吗?关于这个伟大的包,没有太多的文档。
另外,我希望它在甜甜圈的中心有一个默认值。

如果有其他方法可以使用R创建交互式甜甜圈,请让我知道。
提前谢谢你。
发布于 2017-02-10 03:32:44
它看起来像是在甜甜圈中心生成消息的默认函数将总值舍入到最接近的10。
但是您可以使用sunburst的explanation参数自定义此函数。奇怪的是,定制函数(在javascript中)必须以字符串的形式提供。
尝试以下函数:
custom.message = "function (d) {
root = d;
while (root.parent) {
root = root.parent
}
p = (100*d.value/root.value).toPrecision(3);
msg = p+' %<br/>'+d.value+' of '+root.value;
return msg;
}"现在:
sunburst(reports, explanation = custom.message )将生成显示确切总值的甜甜圈。不再需要count参数,因为它由默认的解释函数使用。
custom.message返回的值是html代码。如您所见,我刚刚插入了一个换行符(<br/>)。您可以修改msg返回值以进一步自定义外观。
https://stackoverflow.com/questions/42125828
复制相似问题