【发布时间】:2021-11-28 07:20:32
【问题描述】:
所以我在桑基图的r文档中没有找到任何明确的解决方案,希望有人能帮助我!我要做的就是使链接与源节点的颜色相同,并在将鼠标悬停在其上方时使链接变暗。这是我目前存在的桑基图,不幸的是,由于存在一些保密问题,我无法共享数据。在底部,您会找到我所拥有的情节图像的链接。
dt <- setDT(copy(dt_minors2016))
nodes <- dt[,unique(c(citizen,geo))]
sources <- match(dt[,citizen],nodes)-1
targets <- match(dt[,geo], nodes) -1
values <- dt[,V1]
fig <- plot_ly(
type = "sankey",
#default= 1000,
domain = list(
x = c(0,1),
y = c(0,1)
),
orientation = "h",
valueformat = ".0f",
valuesuffix = "Persons",
node = list(
label = nodes,
# color = colors,
pad = 15,
thickness = 15,
line = list(
color = "black",
width = 0.5
)
),
link = list(
source = sources,
target = targets,
value = values,
color = 'rgba(0,255,255,0.4)'
)
)
fig <- fig %>% layout(
title = "UAM asylum seekers from top 5 origin countries to EU countries - 2016",
font = list(
size = 10
),
xaxis = list(showgrid = F, zeroline = F),
yaxis = list(showgrid = F, zeroline = F),
hovermode = "x unified"
)
fig
【问题讨论】:
-
我有一个解决方案 - 它在 python 中,我不倾向于在 R 中重新编码。它是有情节的,所以 R 中的方法将相同,只是语言语法略有不同。如果您也更新问题以接受 python,我可以提供答案
-
非常感谢您的回复!刚刚编辑了标签,所以现在应该可以工作了:)
-
Here 你可以找到一个使用 plotly 的 R api 的例子。
标签: python r plotly sankey-diagram