[英]Can I rotate the node labels in a Sankey Plot (networkD3::sankeyNetwork)?
I have long(ish) node labels for my Sankey diagram that I would like to rotate so that they can be read top-to-bottom instead of left-to-right.我的桑基图有长(ish)节点标签,我想旋转这些标签,以便可以从上到下而不是从左到右读取它们。 Ideally, I would be able to place these rotated node labels directly over the nodes (rather than the edges).
理想情况下,我可以将这些旋转的节点标签直接放在节点上(而不是边缘)。 Is there anything like the 'srt' option in base R plots?
基本 R 图中是否有类似“srt”选项的内容?
You could add JavaScript to the HTMLWidgets to change certain text attributes/styles...您可以将 JavaScript 添加到 HTMLWidgets 以更改某些文本属性/样式...
library(networkD3)
library(htmlwidgets)
links <- data.frame(
src = c(0, 0, 0, 1, 1, 1, 2, 2, 2),
target = c(3, 4, 5, 3, 4, 5, 3, 4, 5),
value = 1
)
nodes <- data.frame(name = paste0("node", 1:6))
sn <- sankeyNetwork(
Links = links,
Nodes = nodes,
Source = 'src',
Target = 'target',
Value = 'value',
NodeID = 'name',
fontSize = 16,
width = 600,
height = 300,
margin = list("left" = 100)
)
sn <- onRender(
sn,
'
function(el,x) {
d3.select(el)
.selectAll(".node text")
.attr("text-anchor", "middle")
.style("writing-mode", "vertical-rl")
.style("text-orientation", "upright");
}
'
)
sn
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.