Skip to content

Commit 66c3b84

Browse files
Merge pull request #30 from pepijn-devries/work-in-progress
Work in progress
2 parents e2ffddf + caee866 commit 66c3b84

File tree

5 files changed

+25
-23
lines changed

5 files changed

+25
-23
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: ggsankeyfier
22
Type: Package
33
Title: Create Sankey and Alluvial Diagrams Using 'ggplot2'
4-
Version: 0.1.8.0014
4+
Version: 0.1.8.0015
55
Authors@R: c(person("Pepijn", "de Vries", role = c("aut", "cre", "dtc"),
66
email = "pepijn.devries@outlook.com",
77
comment = c(ORCID = "0000-0002-7961-6646")),

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ggsankeyfier v0.1.8.0014
1+
ggsankeyfier v0.1.8.0015
22
-------------
33

44
* Added better stacking order features

R/position_helpers.r

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
)
1414
}
1515
data |>
16+
dplyr::rename(dplyr::any_of(c(node_id = "group"))) |>
1617
.group_across("PANEL", "x", "node_id", "connector") |>
1718
dplyr::summarise(node_size = sum(.data$y)) |>
1819
.group_across("PANEL", "x", "node_id") |>
@@ -151,29 +152,29 @@
151152

152153
rhs <- .group_across(data, "PANEL", "x", "group") |>
153154
dplyr::summarise(y = max(.data$y), .groups = "keep") |>
154-
order_fun()
155+
order_fun() |>
156+
dplyr::rename(y_rhs = "y") |>
157+
.group_across("PANEL", "x") |>
158+
dplyr::arrange(.data$node_order) |>
159+
dplyr::mutate(y_cum = cumsum(.data$y_rhs) -
160+
.data$y_rhs/2,
161+
n_nodes = dplyr::n_distinct(.data$group),
162+
node_rank = dplyr::row_number() - 1,
163+
ytot = sum(.data$y_rhs),
164+
align_offset = .data$y_cum +
165+
(dplyr::row_number() - 1)*params$v_space)
155166

156167
data |>
157168
dplyr::left_join(.stage_params(data, params), "x") |>
158-
dplyr::left_join(
159-
rhs |>
160-
.group_across("PANEL", "x") |>
161-
dplyr::arrange(.data$node_order) |>
162-
dplyr::mutate(y_cum = cumsum(.data$y) -
163-
.data$y/2,
164-
n_nodes = dplyr::n_distinct(.data$group),
165-
ytot = sum(.data$y),
166-
align_offset = .data$ytot +
167-
(.data$n_nodes - 1)*params$v_space),
168-
c("PANEL", "x", "group")) |>
169+
dplyr::left_join(rhs, c("PANEL", "x", "group")) |>
169170
dplyr::arrange(.data$node_order) |>
170171
dplyr::ungroup() |>
171172
dplyr::mutate(
172-
y = .data$y_cum,
173-
ymin = .data$y - .data$node_size/2,
174-
ymax = .data$y + .data$node_size/2,
175-
xmin = .data$x,
176-
xmax = .data$x) |>
173+
y = .data$y_cum,
174+
ymin = .data$y - .data$node_size/2,
175+
ymax = .data$y + .data$node_size/2,
176+
xmin = .data$x,
177+
xmax = .data$x) |>
177178
dplyr::select(!dplyr::any_of("y_cum")) |>
178179
.group_across("PANEL") |>
179180
dplyr::mutate(
@@ -197,9 +198,10 @@
197198
v_space = max(.data$v_space)
198199
) |>
199200
.group_across("PANEL", "x", "connector") |>
201+
dplyr::arrange(.data$node_order) |>
200202
dplyr::mutate(
201-
y_offset = (rank(.data$node_order, ties.method = "first") - 1)*.data$v_space[[1]] +
202-
.data$align_offset,
203+
y_offset = .data$node_rank *
204+
.data$v_space,
203205
x_offset = ifelse(.data$split, .data$h_space*
204206
ifelse(.data$connector == "from", .5, -.5), 0),
205207
y = .data$y + .data$y_offset + params$nudge_y,

README.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ to add all sorts of other layers, such as text and labels.
4343
Furthermore, the data model used by the package allows you to visualise flows that skip stages
4444
or even feedback loops.
4545

46-
And last but not least, in contrast to other packages, `ggsankeyfier` uses proportionate bands.
46+
And last but not least, in contrast to other packages, `ggsankeyfier` uses proportional bands.
4747
In alluvial and Sankey diagrams data quantity flows are represented by
4848
bands that flow across stages. In order to effectively visualise quantities, the width of the
4949
band needs to be proportionate to the quantity. Other packages use a vertically oriented

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Furthermore, the data model used by the package allows you to visualise
3333
flows that skip stages or even feedback loops.
3434

3535
And last but not least, in contrast to other packages, `ggsankeyfier`
36-
uses proportionate bands. In alluvial and Sankey diagrams data quantity
36+
uses proportional bands. In alluvial and Sankey diagrams data quantity
3737
flows are represented by bands that flow across stages. In order to
3838
effectively visualise quantities, the width of the band needs to be
3939
proportionate to the quantity. Other packages use a vertically oriented

0 commit comments

Comments
 (0)