Skip to content

Commit 79394fb

Browse files
Merge pull request #4 from plotly/sankey
sankey
2 parents 7a6e025 + f0f01d6 commit 79394fb

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

r/2017-05-19-sankey.Rmd

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
2-
name: Sankey Diagram
3-
permalink: r/sankey-diagram/
42
description: How to create sankey diagrams in R with Plotly.
5-
layout: base
6-
thumbnail: thumbnail/sankey.jpg
7-
language: r
83
display_as: basic
4+
language: r
5+
layout: base
6+
name: Sankey Diagram
97
order: 16
108
output:
119
html_document:
1210
keep_md: true
11+
permalink: r/sankey-diagram/
12+
thumbnail: thumbnail/sankey.jpg
1313
---
1414

1515
```{r, echo = FALSE, message=FALSE}
@@ -91,8 +91,6 @@ p <- plot_ly(
9191
xaxis = list(showgrid = F, zeroline = F),
9292
yaxis = list(showgrid = F, zeroline = F)
9393
)
94-
95-
p
9694
```
9795

9896

@@ -134,8 +132,6 @@ p <- plot_ly(
134132
xaxis = list(showgrid = F, zeroline = F),
135133
yaxis = list(showgrid = F, zeroline = F)
136134
)
137-
138-
p
139135
```
140136

141137
### Add Links
@@ -239,7 +235,27 @@ p <- plot_ly(
239235
p
240236
```
241237

242-
### Reference
238+
### Define Node Position
239+
The following example sets [node.x](https://plot.ly/r/reference/#sankey-node-x) and `node.y` to place nodes in the specified locations, except in the `snap arrangement` (default behaviour when `node.x` and `node.y` are not defined) to avoid overlapping of the nodes, therefore, an automatic snapping of elements will be set to define the padding between nodes via [nodepad](https://plot.ly/r/reference/#sankey-node-pad). The other possible arrangements are:<font color='blue'> 1)</font> perpendicular <font color='blue'>2)</font> freeform <font color='blue'>3)</font> fixed
243240

244-
See [https://plot.ly/r/reference/#sankey](https://plot.ly/r/reference/#sankey) for more information and options!
241+
```{r}
242+
library(plotly)
243+
p <- plot_ly(
244+
type = "sankey",
245+
arrangement = "snap",
246+
node = list(
247+
label = c("A", "B", "C", "D", "E", "F"),
248+
x = c(0.2, 0.1, 0.5, 0.7, 0.3, 0.5),
249+
y = c(0.7, 0.5, 0.2, 0.4, 0.2, 0.3),
250+
pad = 10), # 10 Pixel
251+
link = list(
252+
source = c(0, 0, 1, 2, 5, 4, 3, 5),
253+
target = c(5, 3, 4, 3, 0, 2, 2, 3),
254+
value = c(1, 2, 1, 1, 1, 1, 1, 2))) %>%
255+
layout(title = "Sankey with manually positioned node")
245256
257+
p
258+
```
259+
260+
### Reference
261+
See [https://plot.ly/r/reference/#sankey](https://plot.ly/r/reference/#sankey) for more information and options!

0 commit comments

Comments
 (0)