1

I'm currently using the R package highcharter to create a simple Sankey diagram from a data set describing funding for multiple projects. The Sankey is quite simple: it has nodes for Funders, nodes for Projects, and flows weighted by annual spending and coloured by level of completion. All of that works, but I cannot seem to get all my node labels to appear. The smallest nodes consistently do not have labels, and I was wondering if I can force all the labels to appear?

My code looks like this:

hchart(df, "sankey",
hcaes(from = Funder, to = Project, weight = AnnualFund, color = Complete)) %>%
hc_plotOptions(sankey = list(dataLabels = list(enabled = TRUE, style = list(fontSize = "12px"))))

I expected the nodes to all be labelled, but the smallest ones consistently do not receive a label even with the plot made full screen. I've tried bumping the font size up and down as well. I feel like I'm missing something small but I cannot get it to work. Everything else about the plot works, though.

EDIT - My data looks like 121 rows of this:

structure(list(
Funder = c(4, 7, 6, 4, 6, 6), 
AnnualFund = c(1913, 365, 1757, 963, 2006, 1876), 
Project = c("G", "A", "C", "E", "B", "E"), 
Complete = c("Late", "NotStarted", "Completed", "Middle", "Late", "Completed")), 
row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"))

Essentially, there are 10 funders, the amounts of annual funding contributed, 7 possible projects, and 5 stages of completion.

  • 1
    Can you share your data or a smaller sample of data using `dput(df)`? That was the people who can help you will be able to run the same code on the same data that you are running. We have no idea what `df` looks like... – Eric Krantz Mar 01 '23 at 23:25
  • @EricKrantz yes, sorry, I added the results of my dput(df) in an edit above. I've actually managed to solve the issue by using hc_size() to set a custom height for the plot, but I now have a different problem. I cannot get hc_legend() to return a legend based on coloring by "Complete" as my original code has. In terms of StackOverflow etiquette, should I pose a separate question and close this one? – Supreet Malhi Mar 03 '23 at 00:42
  • Supreet - Using your example data, I am getting Funder on the left, and Project on the right, with everything labeled correctly. All bands labeled. What do you get with your sample data compared to the full data set? – Eric Krantz Mar 03 '23 at 23:30

0 Answers0