Skip to content

Instantly share code, notes, and snippets.

@mkiang
Created June 3, 2025 04:24
Show Gist options
  • Save mkiang/94f7b0c1ead9343ad0aba4311b49b7e2 to your computer and use it in GitHub Desktop.
Save mkiang/94f7b0c1ead9343ad0aba4311b49b7e2 to your computer and use it in GitHub Desktop.
A visualization of all the different paths from the pick-your-own-adventure book, "Endlessly Ever After".
library(tidyverse)
source(url("https://raw.githubusercontent.com/mkiang/modeling_reemergence/refs/heads/main/code/mk_nytimes.R"))
pages <- tibble::tribble(
~i, ~j, ~attr,
2L, 20L, "top",
2L, 6L, "bottom",
4L, 4L, "happy_ending",
6L, 2L, "top",
6L, 50L, "bottom",
8L, 66L, "top",
8L, 54L, "bottom",
10L, 42L, "top",
10L, 64L, "bottom",
12L, 12L, "sad_ending",
14L, 14L, "medium_ending",
16L, 10L, "top",
16L, 34L, "bottom",
18L, 18L, "sad_ending",
20L, 44L, "top",
20L, 12L, "bottom",
22L, 62L, "top",
22L, 38L, "bottom",
24L, 64L, "top",
24L, 60L, "bottom",
26L, 78L, "top",
26L, 4L, "bottom",
28L, 76L, "top",
28L, 34L, "bottom",
30L, 69L, "top",
30L, 64L, "bottom",
32L, 32L, "sad_ending",
34L, 22L, "top",
34L, 76L, "bottom",
36L, 36L, "medium_ending",
38L, 38L, "happy_ending",
40L, 40L, "sad_ending",
42L, 48L, "top",
42L, 36L, "bottom",
44L, 47L, "top",
44L, 28L, "bottom",
47L, 47L, "sad_ending",
48L, 40L, "top",
48L, 71L, "bottom",
50L, 16L, "top",
50L, 8L, "bottom",
52L, 52L, "sad_ending",
54L, 34L, "top",
54L, 56L, "bottom",
56L, 64L, "top",
56L, 24L, "bottom",
59L, 59L, "medium_ending",
60L, 14L, "top",
60L, 72L, "bottom",
62L, 30L, "top",
62L, 32L, "bottom",
64L, 64L, "medium_ending",
66L, 66L, "happy_ending",
69L, 69L, "medium_ending",
71L, 26L, "top",
71L, 74L, "bottom",
72L, 72L, "happy_ending",
74L, 74L, "sad_ending",
76L, 18L, "top",
76L, 59L, "bottom",
78L, 52L, "top",
78L, 80L, "bottom",
80L, 80L, "happy_ending"
)
p1 <- ggplot() +
geom_point(data = pages |>
filter(i == j),
aes(x = i, y = 1, color = attr),
size = 5,
alpha = 1) +
geom_point(data = pages |>
filter(i != j),
aes(x = i, y = 1),
size = 5,
alpha = .25) +
geom_curve(
data = pages |>
filter(i < j),
aes(x = i, xend = j - .25, y = 1.0005, yend = 1.0005),
curvature = -.7,
angle = 90,
ncp = 10,
arrow = arrow(length = unit(0.2, "cm")),
alpha = .5
) +
geom_curve(
data = pages |>
filter(i > j),
aes(x = i, xend = j + .25, y = .9995, yend = .9995),
curvature = -.7,
angle = 90,
ncp = 10,
arrow = arrow(length = unit(0.2, "cm")),
alpha = .5
) +
coord_cartesian(ylim = c(.99, 1.01)) +
mk_nytimes(legend.position = c(.02, .95)) +
theme(panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
axis.text.y = element_blank()) +
scale_color_manual(NULL,
values = rev(RColorBrewer::brewer.pal(3, "Set1")),
labels = c("Happy ending", "Medium ending", "Sad ending")) +
scale_y_continuous(NULL) +
scale_x_continuous("Page number") +
labs(title = 'Different story paths from "Endlessly Ever After"',
subtitle = "All the different paths and endings from my child's pick-your-own-adventure book.")
ggsave("endlessly_ever_after.jpg",
p1,
width = 10,
height = 6.5,
scale = 1.1,
dpi = 600)
ggsave("endlessly_ever_after.pdf",
p1,
width = 10,
height = 6.5,
scale = 1.1,
device = cairo_pdf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment