Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Controlling colors used by sankey command

    Hello, I am using the sankey command to create a graph showing sources of funds and their destinations (called "departments" in my data). Command works as promised and I get a nice graph. Command allows user to specify colorpalette ("tableau", "economist", "s2", etc.), and that, too works as promised.

    Question: is there another way to specify a set of colors to use for this graph (e.g., "175 39 47" "116 168 159" etc.)? I know the colors I want but have struggled with my limited understanding of Stata's use/storage of palettes, schemes, and so on. The command seems to accept only "saved" colorpalettes. I've spent time chasing rabbits (ideas) like writing and saving my own colorpalette files, schemes, and so on, but I have not been able to make it happen.

    I am using StataNow/SE 19.5 for Windows.


    Here is what the data look like, with "amount" (which is $) going from "sourcetype" to "department":
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str25 department str7 sourcetype double amount
    "All Other" "Bonds" 967.541617
    "All Other" "Federal" 0
    "All Other" "Paygo" 168.1999
    "Capital Development Board" "Bonds" 9501.310781
    "Capital Development Board" "Federal" 0
    "Capital Development Board" "Paygo" 156.51910700000002
    "Comm. & Econ. Opportunity" "Bonds" 5388.889077
    "Comm. & Econ. Opportunity" "Federal" 836.159011
    "Comm. & Econ. Opportunity" "Paygo" 459.8257
    "Environmental Protection" "Bonds" 216.715961
    "Environmental Protection" "Federal" 785.96
    "Environmental Protection" "Paygo" 4223.505911
    "Natural Resources" "Bonds" 380.851248
    "Natural Resources" "Federal" 195.15
    "Natural Resources" "Paygo" 465.646413
    "Transportation" "Bonds" 8209.178414
    "Transportation" "Federal" 782.744254
    "Transportation" "Paygo" 19814.331315
    end
    Here is my code, specifying use of the "tableau" colorpalette:

    sankey amount ,
    from(source) to(department) labangle(0) labposition(3) format(%8.1fc) labgap(10) offset(30) novalues
    palette(tableau)
    sort1(name,reverse)
    title("FY 2026 Capital Budget (millions of $): All Appropriations")
    subtitle("Sources of Funds vs. Departments")
    note("Source: FY2026 Final Enacted Capital Budget Data.xlsx, derived from GOMB.")
    saving(sankey2all.gph, replace);


    Thank-you for any suggestions you may have.
    Attached Files

  • #2
    sankey is from SSC (and perhaps elsewhere). It was written by Asjad Naqvi who is a member here. He may react to that ping but is perhaps more effectively addressed by direct email or a post on Medium.

    Comment


    • #3
      Thank-you, Nick.

      Comment


      • #4
        Thank you Nick Cox for the ping!

        Dear Paula Worthington,

        There is a way of passing colors from RGB codes to visualization programs but it is a bit convoluted since it involves defining a custom program. See https://repec.sowi.unibe.ch/stata/pa...g-started.html for details on custom palettes.

        A straightforward way is to convert the RGB values to hex codes, e.g. using Google color picker. Given the color codes you have provided, one gets these values:

        "175 39 47": #af272f
        "116 168 159": #74a89f

        And we can use these directly:

        Code:
        sankey amount,    ///
        from(source) to(department) labangle(0) labposition(3) format(%8.1fc) labgap(2) offset(25) novalues    ///
        palette(#af272f #74a89f)    ///
        sort1(name,reverse)    ///
        title("FY 2026 Capital Budget (millions of $): All Appropriations")    ///
        subtitle("Sources of Funds vs. Departments")    ///
        note("Source: FY2026 Final Enacted Capital Budget Data.xlsx, derived from GOMB.")

        Hope this helps! For faster responses please open and issue on GitHub. The helpfile contains all the info on how to report or request package related issues.

        A.
        Last edited by Asjad Naqvi; 02 Nov 2025, 13:08.

        Comment

        Working...
        X