diff --git a/R/sankeyNetwork.R b/R/sankeyNetwork.R index 0eca7fb..fdec38f 100644 --- a/R/sankeyNetwork.R +++ b/R/sankeyNetwork.R @@ -61,7 +61,7 @@ NULL #' @param fontFamily font family for the node text labels. Default is 'Arial'. #' @param fontColor font color for the node text labels. #' @param nodeWidth numeric width of each node. -#' @param nodePadding numeric essentially influences the width height. Default is 12. +#' @param nodePadding numeric essentially influences the width height. By default, it's the same as the fontSize parameter. #' @param nodeStrokeWidth numeric width of the stroke around nodes. #' @param nodeCornerRadius numeric Radius for rounded nodes. #' @param numberFormat number format in tooltips - see https://github.com/d3/d3-format for options. Default is ',.1f'. @@ -85,8 +85,8 @@ NULL #' @param linkColor numeric Color of links. #' @param linkOpacity numeric Opacity of links. #' @param linkGradient boolean Add a gradient to the links? -#' @param dragX boolean Allow moving nodes along the x-axis? -#' @param dragY boolean Allow moving nodes along the y-axis? +#' @param dragX boolean Allow moving nodes along the x-axis? Default is FALSE. +#' @param dragY boolean Allow moving nodes along the y-axis? Default is TRUE. #' @param nodeShadow boolean Add a shadow to the nodes? #' @param xScalingFactor numeric Scale the computed x position of the nodes by this value. #' @param xAxisDomain character[] If xAxisDomain is given, an axis with those value is @@ -127,7 +127,7 @@ sankeyNetwork <- function(Links, fontFamily = "Arial", fontColor = NULL, nodeWidth = 15, - nodePadding = 12, + nodePadding = NULL, nodeStrokeWidth = 1, nodeCornerRadius = 0, margin = NULL, @@ -138,7 +138,7 @@ sankeyNetwork <- function(Links, doubleclickTogglesChildren = FALSE, xAxisDomain = NULL, dragX = FALSE, - dragY = FALSE, + dragY = TRUE, height = 500, width = 800, iterations = 32, @@ -167,6 +167,11 @@ sankeyNetwork <- function(Links, # Hack for UI consistency. Think of improving. colourScale <- as.character(colourScale) + # Change nodePadding to fontSize if it is NULL + if (is.null(nodePadding)) { + nodePadding <- fontSize + } + # If tbl_df convert to plain data.frame Links <- tbl_df_strip(Links) Nodes <- tbl_df_strip(Nodes) diff --git a/docs/articles/Examples.html b/docs/articles/Examples.html index de3145e..61b485e 100644 --- a/docs/articles/Examples.html +++ b/docs/articles/Examples.html @@ -103,8 +103,8 @@
You can have link-specific and node-specific colors:
@@ -188,14 +188,14 @@Link color & Node color NodeColor = "nodecolor", units = "mio. people", )
You can enforce the vertical order of nodes via NodePosY
-and their horizontal position via NodePosX
:
You can enforce the vertical order of nodes via
+NodePosY
.
links <- tribble(
~source, ~target, ~value,
@@ -207,12 +207,12 @@ Node Positioning)
nodes <- tribble(
- ~id, ~label, ~yorder, ~xpos,
- 0, "German residents", 1, 0,
- 1, "Berlin Residents", 1, 1,
- 2, "Other cities (>100k)", 3, 1,
- 3, "Non-Metropolitans", 2, 2,
- 4, "Metropolitans (>100k)", 1, 2
+ ~id, ~label, ~yorder,
+ 0, "German residents", 1,
+ 1, "Berlin Residents", 1,
+ 2, "Other cities (>100k)", 3,
+ 3, "Non-Metropolitans", 2,
+ 4, "Metropolitans (>100k)", 1
)
sankeyNetwork(
@@ -225,9 +225,37 @@ Node Positioning NodeID = "label",
NodePosY = "yorder"
)
-sankeyNetwork(
+
+
+
You can enforce a node’s horizontal position via
+NodePosX
and label the x-Axis via xAxisDomain
.
+However, as pointed out in this
+issue, changing fontSize
unfortunately does not affect
+xAxisDomain
.
+links <- tribble(
+ ~source, ~target, ~value,
+ 0, 1, 3.7,
+ 0, 2, 22.9,
+ 0, 3, 57.7,
+ 1, 4, 3.7,
+ 2, 4, 22.9
+)
+
+nodes <- tribble(
+ ~id, ~label, ~xpos,
+ 0, "German residents", 0,
+ 1, "Berlin Residents", 1,
+ 2, "Other cities (>100k)", 1,
+ 3, "Non-Metropolitans", 2,
+ 4, "Metropolitans (>100k)", 2
+)
+
+sankeyNetwork(
Links = links,
Source = "source",
Target = "target",
@@ -235,10 +263,11 @@ Node Positioning units = "mio. people",
Nodes = nodes,
NodeID = "label",
- NodePosX = "xpos", # only works in combination with align = "none" or align = "left"
+ NodePosX = "xpos",
+ xAxisDomain = c("Germany", "Berlin vs. other cities", "City vs. rural")
)
numeric essentially influences the width height. Default is 12.
numeric essentially influences the width height. By default, it's the same as the fontSize parameter.
boolean Allow moving nodes along the x-axis?
boolean Allow moving nodes along the x-axis? Default is FALSE.
boolean Allow moving nodes along the y-axis?
boolean Allow moving nodes along the y-axis? Default is TRUE.