Changing trace colors in Sankey

Hi! When I try to change the color of the traces in my Sankey map, they all become opaque. I’d like to change the colors but preserve the transparency. Is anyone able to suggest code to fix that?

Hi @butteredtoast

It may be easier for users to give suggestion if you share your code. That said, have you tried something like:

library(plotly)

plot_ly(
  type='sankey',
  alpha = 0.1,
  node = list(
    pad = 15,
    thickness = 20,
    line = list(
      color = "black",
      width = 0.5
    ),
    label = c("A1", "A2", "B1", "B2", "C1", "C2"),
    color = 'rgba(255,0,255,0.8)'
  ),
  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)'
  )
)

Thank you! That did the trick!

Any idea how to change the opacity back to 1 on hover? The default behaviour is to make the link more opaque on hover, but if I select the color manually, on hover the link becomes more transparent rather than more opaque, which does not make a lot of sense

EDIT: I looked into the .js library and it seems LinkHoverStyle alpha is hardcoded at 0.4. This value makes sense for the default grey/black but not for many other color. Would it be possible to access this property on the R and Python library?

2 Likes

I have a similar issue and opened a topic linked below, we’ll see if anything comes of it.

Basically my issue is that a 0.4 difference in opacity is not noticeable on a sankey with more than just a few nodes. When hovered over, it becomes hard to follow the data from the start to the end – which kind of defeats the purpose of a sankey imo.

1 Like