Plotting pi digits as connection bundles with ggraph

Viewed 29

I'm looking to plot the digits of Pi as heirarchical edge bundles, as shown in this image

enter image description here

Here, the digits of Pi are grouped by their colour, and then each digit has an edge drawn to the digit that follows it (i.e., if Pi is 3.141, then 3 would have an edge drawn to 1, 1 would have an edge to 4, and so on through the digits).

This is the code I have so far

library(ggraph)
library(tidygraph)

dat_lagged <- structure(list(line = c(1L, 3L, 4L, 5L, 6L, 7L), digit = c("3", 
"1", "4", "1", "5", "9"), digit_lagged = c("1", "4", "1", "5", 
"9", "2"), group = c("3", "1", "4", "1", "5", "9")), row.names = c(NA, 
-6L), class = c("tbl_df", "tbl", "data.frame"))

from <- as.numeric(dat_lagged$digit)
to <- as.numeric(dat_lagged$digit_lagged)

ggraph(dat_lagged, 'dendrogram', circular = TRUE) +
  geom_conn_bundle(aes(colour = stat(group)),
                   data = get_con(from, to),
                   edge_alpha = 0.25)

However this is throwing the error

Error in if (is.numeric(v) && any(v < 0)) { : 
  missing value where TRUE/FALSE needed
0 Answers
Related