Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
568 views
in Technique[技术] by (71.8m points)

Change the color of specific node labels in R plotly sankey diagram

I wrote a program that puts together a sankey diagram using the plotly tools, but I'd like to change the font color of some of the node labels so that some specific nodes stand out. My nodes data frame already has a column for color with the values that I would like. I can change the color of the nodes themselves, but some of them are displayed too thin for it to be useful (and it just doesn't look as good as plotly's colors), which is why I'd like to change the font color. I've already spent a couple of hours digging through documentation on sankey diagrams and couldn't find anything on how to change font colors. Here is my current code for building the diagram:

trace1 <- list(
    link = list(
        value = links$n
        source = links$IDsource,
        target = links$IDtarget
    ),
    node = list(
        pad = 60,
        line = list(
            color = "black",
            width = 0.5
        ),
        label = nodes$name,
        thickness = 30
    ),
    type = "sankey",
    domain = list(
        x = c(0,1),
        y = c(0,1)
    ),
    orientation = "h",
    valueformat = ".0f"
)
layout <- list(
    font = list(size = 30),
    title = "Traffic Map",
    margin = c(t = 1)
)
p <- plot_ly()
p <- add_trace(p , link = trace1$link, node = trace1$node, type=trace1$type, domain = trace1$domain, orientation = trace1$orientation, valueformat = trace1$valueformat)
p <- layout(p, font=layout$font, title=layout$title, margin = layout$margin)
htmlwidgets::saveWidget(p, file = "SankeyDiagram.html")

Thank you for your time and help!

question from:https://stackoverflow.com/questions/65892956/change-the-color-of-specific-node-labels-in-r-plotly-sankey-diagram

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...