Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visualize all possible syllable combinations

I take the 4 syllables " "ha", "mu", "ra", "bi"

Using the following code, I can find out all combinations that can be made with these 4 syllables:

library(dplyr)

objects <- c("ha", "mu", "ra", "bi")
combinations <- expand.grid(objects, objects, objects, objects)

combinations$name <- apply(combinations, 1, function(x) {
    paste(x, collapse = "-")
})

combinations$id = 1:nrow(combinations)

combinations <- select(combinations, id, everything())

Now, using the igraph package, I am trying to make a network/graph that visualizes all possible combinations of these syllables. This would look something like this:

enter image description here

Can someone please show me how I can restructure my data to then create this visualization?

like image 237
stats_noob Avatar asked Oct 14 '25 09:10

stats_noob


1 Answers

Here is an example with 3 layers

objects <- c("ha", "mu", "ra", "bi")

n <- 3 # height of tree
N <- sum(length(objects)^(0:n)) # total number of vertices, including a virtual root

make_tree(N, length(objects)) %>%
  delete.vertices(1) %>%
  set_vertex_attr("name", value = rep(objects, length.out = vcount(.))) %>%
  plot(layout = layout_as_tree)

enter image description here

like image 84
ThomasIsCoding Avatar answered Oct 17 '25 02:10

ThomasIsCoding