|
| 1 | +library(ggraph) |
| 2 | +library(tidygraph) |
| 3 | +library(hexSticker) |
| 4 | + |
| 5 | +dat <- |
| 6 | + tibble::tribble( |
| 7 | + ~from, ~to, |
| 8 | + "SEM", "BGU", |
| 9 | + "SEM", "S1", |
| 10 | + "SEM", "S2", |
| 11 | + "SEM", "...", |
| 12 | + "SEM", "S40", |
| 13 | + "Psych", "SEM", |
| 14 | + "Psych", "BGU" |
| 15 | +) %>% |
| 16 | + as_tbl_graph() %E>% |
| 17 | + mutate(dir = c("<", "<", "<", "<", "<", "<", "<>")) %N>% |
| 18 | + arrange(name) %>% |
| 19 | + mutate(type = c(rep("Obs",6), "Lat")) |
| 20 | + |
| 21 | +dat %>% |
| 22 | + as.data.frame() |
| 23 | + |
| 24 | +arrow_cap <- circle(4, 'mm') |
| 25 | +label.padding <- unit(0.3,"lines") |
| 26 | + |
| 27 | +sem_p <- ggraph(dat, layout = "manual", |
| 28 | + x = c(1, 2.5, 2.5, 1, 1, 1, 2)/40, |
| 29 | + y = -c(2.75, 3.5, 1.5, 1.75, 2.25, 3.25, 2.5)/80) + |
| 30 | + # edges |
| 31 | + geom_node_label(aes(filter = type=="Obs", |
| 32 | + label = name), |
| 33 | + label.r = unit(0, "lines"), |
| 34 | + label.padding = label.padding) + |
| 35 | + geom_node_label(aes(filter = type!="Obs", |
| 36 | + label = name), |
| 37 | + label.r = unit(0.4, "lines"), |
| 38 | + label.padding = label.padding) + |
| 39 | + # edges |
| 40 | + geom_edge_link(aes(filter = dir == "<"), |
| 41 | + arrow = arrow(20, unit(.1, "cm"), type = "closed"), |
| 42 | + start_cap = arrow_cap, |
| 43 | + end_cap = arrow_cap) + |
| 44 | + geom_edge_arc(aes(filter = dir == "<>"), |
| 45 | + arrow = arrow(20, unit(.1, "cm"), type = "closed", ends = "both"), |
| 46 | + start_cap = arrow_cap, |
| 47 | + end_cap = arrow_cap) + |
| 48 | + # theme_bw() + |
| 49 | + theme_transparent() + |
| 50 | + coord_cartesian(xlim = c(0.02, 0.07), |
| 51 | + ylim = -c(0.015, 0.047)) |
| 52 | + |
| 53 | + |
| 54 | +sticker(sem_p, package="SEM - Practical Applications in R", |
| 55 | + filename = "BGUHex.png", |
| 56 | + s_x = 0.9, s_y = 0.8, s_width = 1.6, s_height = 1.2, |
| 57 | + p_color = "white", p_size = 8, |
| 58 | + h_color = "grey", h_fill = "orange", |
| 59 | + spotlight = TRUE, l_y = 1.2) |
0 commit comments