Comments (5)
Hello @davidsjoberg thank you for this nice package. I have the same need of labeling the flows, I tried to retrieve the flow positions from the figure layers and add corresponding labels to them, but not succeed yet ... I'am wondering if you had already implemented this function or maybe have any suggestion on how to do this properly?
I come back here to answer my own question, and here is a solution to add flow size to each flow:
Suppose df
is the data returned by the function make_long()
, and p
is the sankey plot you've made based on df
# get flow size for each flow
`flow_labels <- df %>% group_by(x, node, next_x, next_node) %>% tally() %>% drop_na()
# get corresponding positions of flows from the sankey plot
flow_info <- layer_data(p) %>% select(xmax, flow_start_ymax, flow_start_ymin) %>% distinct() # get flow related key positions related from the plot
flow_info <- flow_info[with(flow_info, order(xmax, flow_start_ymax)), ] # order the positions to match the order of flow_labels
rownames(flow_info) <- NULL # drop the row indexes
flow_info <- cbind(as.data.frame(flow_info), as.data.frame(flow_labels)) # bind the flow positions and the corresponding labels
# add labels to the flows
for (i in 1:nrow(flow_info)){
p <- p + annotate("text", x = flow_info$xmax[i],
y = (flow_info$flow_start_ymin[i] + flow_info$flow_start_ymax[i])/2,
label = sprintf("%d", flow_info$n[i]), hjust = -1,
size = 3
)
}
It's not a very elegant solution, but it works for me.
from ggsankey.
from ggsankey.
Great that you are working on that option!
I think there are 3 reasonable possibilities for the labels: Directly behind the source node, directly before the end node or in the middle of two nodes. I think the first two options will usually be most reasonable since these areas tend to be more homogeneous and not as messy as the midpoint between two nodes where the flows cross each other. The best option for me would be directly behind the source node in the middle (y-direction) of the flow.
from ggsankey.
Thanks much for this fantastic package, @davidsjoberg. I'm wondering if you've had a chance to build in this ^ functionality yet; I'm considering MacGyver-ing the code, but figured I'd check in before I do!
from ggsankey.
Hello @davidsjoberg thank you for this nice package. I have the same need of labeling the flows, I tried to retrieve the flow positions from the figure layers and add corresponding labels to them, but not succeed yet ...
I'am wondering if you had already implemented this function or maybe have any suggestion on how to do this properly?
from ggsankey.
Related Issues (20)
- how can I joint ggsankey and a dotplot? HOT 2
- missing dplyr:: call
- How to skip nodes with NA value in ggsankey? HOT 2
- ggsankey not available on CRAN? HOT 1
- Labels always get misaligned HOT 3
- Using ggsankey in Shiny HOT 1
- Flow.fill isn't working HOT 2
- Can't install package HOT 3
- Trouble With Data Length in geom_alluvial
- Ggsankey citation? HOT 2
- plotting categorical values along with numeric values
- question: What makes a ribbon to cross over other ribbons in sankey plot ? HOT 4
- strange grey nodes bars HOT 1
- Left and right shift of node labels to put them beside the nodes HOT 2
- Alluvial, not Sankey. How should the input data be structured to create a flow chart?
- can't install ggsankey HOT 8
- Availability on CRAN/Bioconductor HOT 3
- is it true that one node can connect with one next-node by only one flow? (how to merge two plots?)
- Upload ggsankey package on conda
- Labels too wide for alluvial plot
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ggsankey.