Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(tidyverse)
- library(igraph)
- g <- make_lattice(c(5, 5))
- ego(g, order = 1, mindist = 1)
- head_of(g, E(g))
- he <- ego(g, order = 1, mindist = 1, nodes = head_of(g, E(g)))
- te <- ego(g, order = 1, mindist = 1, nodes = tail_of(g, E(g)))
- thirdN <- map2(te, he, function(x, y){c(x,y) %>% unique %>% as.numeric()})
- elSL <- as_data_frame(g) %>%
- as.tibble() %>%
- mutate(third = thirdN) %>%
- unnest() %>%
- filter(third != from,
- third != to) %>%
- mutate(fourth = ego(g, order = 1, mindist = 1, nodes = third) %>%
- map(as.numeric)) %>%
- unnest() %>%
- filter(fourth != from,
- fourth != to) %>%
- mutate(fifth = ego(g, order = 1, mindist = 1, nodes = fourth) %>%
- map(as.numeric)) %>%
- unnest() %>%
- filter(fifth != from,
- fifth != to,
- fifth != third) %>%
- apply(1, sort) %>%
- t %>%
- as.tibble() %>%
- distinct() %>%
- mutate_all(as.integer)
- elY <- as_data_frame(g) %>%
- as.tibble() %>%
- mutate(third = thirdN) %>%
- unnest() %>%
- filter(third != from,
- third != to) %>%
- {
- branch <<- ego(g, order = 1, mindist = 1, nodes = .$third)
- branchData <<- mutate(., fourth = branch %>% map(as.numeric))
- branchData
- } %>%
- unnest() %>%
- filter(fourth != from,
- fourth != to) %>%
- left_join(rename(branchData, fifth = fourth)) %>%
- unnest() %>%
- filter(fifth != from,
- fifth != to,
- fifth != fourth) %>%
- apply(1, sort) %>%
- t %>%
- as.tibble() %>%
- distinct() %>%
- mutate_all(as.integer) %>%
- anti_join(elSL)
- elT <- as_data_frame(g) %>%
- as.tibble() %>%
- mutate(third = thirdN) %>%
- unnest %>%
- filter(third != from,
- third != to) %>%
- left_join(rename(., fourth = third)) %>%
- filter(fourth != third) %>%
- left_join(rename(., fifth = third) %>% select(-fourth)) %>%
- filter(fifth != third,
- fifth != fourth) %>%
- apply(1, sort) %>%
- t %>%
- as.tibble() %>%
- distinct() %>%
- anti_join(elSL) %>%
- anti_join(elY) %>%
- mutate_all(as.integer)
- set.seed(4)
- plot(g)
- saveGIF({
- ani.options(interval = 0.2)
- for (i in seq_along(elY$V1)) {
- set.seed(5)
- plot(g,
- vertex.color = ifelse(V(g) %in% unlist(elY[i,]), 'skyblue', 'pink')
- )
- title("All Y length 5")
- ani.pause()
- }}, movie.name = "Ylength5.gif", ani.width = 600, ani.height = 600)
- saveGIF({
- ani.options(interval = 0.2)
- for (i in seq_along(elSL$V1)) {
- set.seed(5)
- plot(g,
- vertex.color = ifelse(V(g) %in% unlist(elSL[i,]), 'skyblue', 'pink')
- )
- title("All Straight Line length 5")
- ani.pause()
- }}, movie.name = "SLlength5.gif", ani.width = 600, ani.height = 600)
- saveGIF({
- ani.options(interval = 0.2)
- for (i in seq_along(elT$V1)) {
- set.seed(5)
- plot(g,
- vertex.color = ifelse(V(g) %in% unlist(elT[i,]), 'skyblue', 'pink')
- )
- title("All T Line length 5")
- ani.pause()
- }}, movie.name = "Tlength5.gif", ani.width = 600, ani.height = 600)
Add Comment
Please, Sign In to add comment