Last active
February 8, 2019 13:56
-
-
Save schochastics/cf1b8416d314b2c10b7ff3dff1933333 to your computer and use it in GitHub Desktop.
radial layout with groups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(igraph) | |
library(smglr) | |
library(tidyverse) | |
library(ggraph) | |
g <- sample_islands(9,40,0.2,10) | |
g <- simplify(g) | |
V(g)$grp <- rep(1:9,each=40) | |
el <- get.edgelist(g) | |
E(g)$col <- case_when( | |
V(g)$grp[el[,1]]==1 & V(g)$grp[el[,2]] == 1 ~ 1, | |
V(g)$grp[el[,1]]==2 & V(g)$grp[el[,2]] == 2 ~ 2, | |
V(g)$grp[el[,1]]==3 & V(g)$grp[el[,2]] == 3 ~ 3, | |
V(g)$grp[el[,1]]==4 & V(g)$grp[el[,2]] == 4 ~ 4, | |
V(g)$grp[el[,1]]==5 & V(g)$grp[el[,2]] == 5 ~ 5, | |
V(g)$grp[el[,1]]==6 & V(g)$grp[el[,2]] == 6 ~ 6, | |
V(g)$grp[el[,1]]==7 & V(g)$grp[el[,2]] == 7 ~ 7, | |
V(g)$grp[el[,1]]==8 & V(g)$grp[el[,2]] == 8 ~ 8, | |
V(g)$grp[el[,1]]==9 & V(g)$grp[el[,2]] == 9 ~ 9, | |
TRUE ~ 10 | |
) | |
xy <- layout_with_centrality(g,V(g)$grp) | |
ggraph(g,layout = "manual",node.positions = data.frame(x = xy[,1], y = xy[,2])) + | |
geom_edge_link(aes(col=factor(col)),n=2,alpha=0.4)+ | |
geom_node_point(aes(fill=factor(grp)),shape=21)+ | |
theme_graph()+ | |
coord_fixed()+ | |
scale_fill_manual(values = c("#458B74", "#8A2BE2", "#CD3333", "#8B7355", "#458B00", | |
"#EE7600", "#FF6EB4", "#CDCD00", "#6495ED"))+ | |
scale_edge_color_manual(values = c("#458B74", "#8A2BE2", "#CD3333", "#8B7355", "#458B00", | |
"#EE7600", "#FF6EB4", "#CDCD00", "#6495ED","grey66"))+ | |
theme(legend.position = "none") |
Author
schochastics
commented
Feb 8, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment