R plotly sankey节点不透明度

时间:2018-08-03 20:49:21

标签: r plotly

默认的sankey图表具有灰色和透明的链接,以便您可以看到重叠的链接。我正在尝试在下面的示例Sankey图表中的链接中添加颜色;有没有办法使链接部分透明,以便可以看到重叠的链接?

p <- plot_ly(
  type = "sankey",
  orientation = "h",

  node = list(
    label = c("A1", "A2", "B1", "B2", "C1", "C2"),
    color = c("blue", "blue", "blue", "blue", "blue", "blue"),
    pad = 15,
    thickness = 20,
    line = list(
      color = "black",
      width = 0.5
    )
  ),

  link = list(
    source = c(0,1,0,2,3,3),
    target = c(2,3,3,4,4,5),
    value =  c(8,4,2,8,4,2),
    color = c("blue", "red", "green", "yellow","blue", "red"),
    opacity = c(0.5, 0.5, 0.5, 0.5, 0.5, 0.5),
    alpha = 0.5
  )
) %>% 
  layout(
    title = "Basic Sankey Diagram",
    font = list(
      size = 10
    )
  )

1 个答案:

答案 0 :(得分:0)

我有完全一样的问题。您可以直接在颜色中指定不透明度,如下所示:

link = list(
    source = c(0,1,0,2,3,3),
    target = c(2,3,3,4,4,5),
    value =  c(8,4,2,8,4,2),
    color = 'rgba(0,255,255,0.4)'
)

您还可以放入一个数组中

color = c("rgba(0,0,255,0.4)", "rgba(255,0,0,0.4)")