Skip to content

Commit

Permalink
add sankey graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
hansvancalster committed Mar 15, 2024
1 parent 108b80c commit cf581e1
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions source/scripts/test_sampling_design.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,68 @@ join_levels <- cats(temporal_stratification)[[1]] %>%
levels(temporal_stratification) <- join_levels
coltab(temporal_stratification) <- NULL

# all transitions

df <- join_levels %>%
ggsankey::make_long(
lg2013, lg2016, lg2019,
value = count
)

df2 <- df %>%
group_by(x, node) %>%
summarise(n = sum(value))

df3 <- df %>%
left_join(df2)

p <- df3 %>%
ggplot(aes(x = x,
next_x = next_x,
node = node,
next_node = next_node,
fill = factor(node),
label = paste0(node,": n = ", n),

Check warning on line 166 in source/scripts/test_sampling_design.R

View workflow job for this annotation

GitHub Actions / check project with checklist

file=source/scripts/test_sampling_design.R,line=166,col=34,[commas_linter] Commas should always have a space after.
value = value)) +
geom_sankey(alpha = 0.5) +
geom_sankey_label(alpha = 0.5, colour = "black") +
theme_sankey() +
theme(legend.position = "none")

p

# only changes

df <- join_levels %>%
filter(stable == "changed") %>%
ggsankey::make_long(
lg2013, lg2016, lg2019,
value = count
)

df2 <- df %>%
group_by(x, node) %>%
summarise(n = sum(value))

df3 <- df %>%
left_join(df2)

p <- df3 %>%
ggplot(aes(x = x,
next_x = next_x,
node = node,
next_node = next_node,
fill = factor(node),
label = paste0(node,": n = ", n),

Check warning on line 197 in source/scripts/test_sampling_design.R

View workflow job for this annotation

GitHub Actions / check project with checklist

file=source/scripts/test_sampling_design.R,line=197,col=34,[commas_linter] Commas should always have a space after.
value = value)) +
geom_sankey(alpha = 0.5) +
geom_sankey_label(alpha = 0.5, colour = "black") +
theme_sankey() +
theme(legend.position = "none")

p



# map showing stable (TRUE) vs changed (FALSE)
activeCat(temporal_stratification) <- "stable"
Expand Down

0 comments on commit cf581e1

Please sign in to comment.