我正在使用ggsankey制作一个Sankey图,当标签在 node 上重叠时,很难让标签可见.我有三个 node ,希望移动左侧的标签,这样它就不会与 node 重叠,而是位于 node 的左侧.我希望中间的 node 保持在 node 的中心,并且我希望移动右边的标签,以便位于右边的 node 的右边.
我可以使用geom_sankey_label和hjust让所有标签移动位置,但我不知道如何分别移动每个 node 上的标签.我甚至不知道是否有可能做我想做的事情.
我的代码和这个非常相似—
df <- mtcars %>%
make_long(cyl, vs, am, gear, carb)
ggplot(df, aes(x = x, next_x = next_x, node = node, next_node = next_node, fill = factor(node), label = node)) +
geom_sankey(flow.alpha = .6,
node.color = "gray30",
space = 20) +
geom_sankey_label(size = 3,
color = "white",
fill = "gray40",
hjust = 0,
position = position_nudge(x = 0.1),
space = 20) +
scale_fill_viridis_d() +
theme_sankey(base_size = 18) +
labs(x = NULL) +
theme(legend.position = "none",
plot.title = element_text(hjust = .5)) +
ggtitle("Car features")
sankey plot with labels moved off nodes
我希望它看起来像这个草图:enter image description here