2424# ' @inheritParams ggplot2::geom_segment
2525# ' @param slope Slope parameter (`numeric`) for the Bezier curves used to depict the edges.
2626# ' Any value between 0 and 1 will work nicely. Other non-zero values will also work.
27+ # ' @param curve_weight Places weight on the Bezier curve. Values close to zero will
28+ # ' pull the inflection point of the curve towards outgoing nodes. Values close to one
29+ # ' will pull them towards incoming nodes. The default is 0.5, which will place the
30+ # ' inflection point exactly in the middle of the connecting nodes.
2731# ' @param ncp Number of control points on the Bezier curve that forms the edge. Larger
2832# ' numbers will result in smoother curves, but cost more computational time. Default is
2933# ' 100.
@@ -49,17 +53,22 @@ GeomSankeyedge <-
4953 draw_panel = .draw_edges ,
5054 setup_data = function (data , params ) {
5155 data <- GeomSankeysegment $ setup_data(data , params )
52- data <- data | >
53- dplyr :: mutate(
54- slope = params $ slope ,
55- ncp = params $ ncp
56+ unique_x <- unique(data $ x ) | > sort()
57+ curve_params <-
58+ data.frame (
59+ x = unique_x ,
60+ slope = rep(params $ slope , length.out = length(unique_x )),
61+ curve_weight = rep(params $ curve_weight , length.out = length(unique_x )),
62+ ncp = params $ ncp
5663 )
64+ data <- data | >
65+ dplyr :: left_join(curve_params , by = " x" )
5766 return (data )
5867 },
5968 rename_size = FALSE ,
6069 default_aes = c(GeomSankeysegment $ default_aes , waist = 1 ),
6170 draw_key = draw_key_sankeyedge ,
62- extra_params = c(" na.rm" , " slope" , " ncp" )
71+ extra_params = c(" na.rm" , " slope" , " curve_weight " , " ncp" )
6372 )
6473
6574# ' @name geom_sankeyedge
@@ -68,7 +77,7 @@ GeomSankeyedge <-
6877geom_sankeyedge <-
6978 function (mapping = NULL , data = NULL , stat = " sankeyedge" ,
7079 position = " sankey" , na.rm = FALSE , show.legend = NA ,
71- slope = 0.5 , ncp = 100 ,
80+ slope = 0.5 , curve_weight = 0.5 , ncp = 100 ,
7281 width = " auto" , align = c(" bottom" , " top" , " center" , " justify" ),
7382 order = c(" ascending" , " descending" , " ascending+" , " descending+" , " as_is" ),
7483 h_space = " auto" , v_space = 0 ,
@@ -82,6 +91,7 @@ geom_sankeyedge <-
8291 ggplot2 :: layer(
8392 geom = GeomSankeyedge , mapping = mapping , data = data , stat = stat ,
8493 position = position , show.legend = show.legend , inherit.aes = inherit.aes ,
85- params = list (na.rm = na.rm , slope = slope , ncp = ncp , ... )
94+ params = list (na.rm = na.rm , slope = slope , curve_weight = curve_weight ,
95+ ncp = ncp , ... )
8696 )
8797 }
0 commit comments