我可以在 R 中的 ggraph/ggplot2 中的弧形图中分隔两组顶点吗?
Can I separate two groups of vertices in an arc plot in ggraph/ggplot2 in R?
我使用以下代码通过两个不同的电极得到了一张很棒的图表:
elec <- c("Fp1","Fp2","F7","F3","Fz","F4","F8","FC5","FC1","FC2","FC6","C3","Cz","C4","CP5","CP1","CP2","CP6","P7","P3","Pz","P4","P8","POz","Oz",
"Fp1","Fp2","F7","F3","Fz","F4","F8","FC5","FC1","FC2","FC6","C3","Cz","C4","CP5","CP1","CP2","CP6","P7","P3","Pz","P4","P8","POz","Oz")
edgelist <- get.edgelist(net)
# get vertex labels
label <- get.vertex.attribute(net, "name")
# get vertex groups
group <- get.vertex.attribute(net, "group")
# get vertex fill color
fill <- get.vertex.attribute(net, "color")
# get family
family <- get.vertex.attribute(net, "family")
# get vertex degree
degrees <- degree(net)
# data frame with groups, degree, labels and id
nodes <- data.frame(group, degrees, family, label, fill, id=1:vcount(net))
nodes$family <- factor(nodes$family, levels = unique(nodes$family))
nodes$label <- factor(nodes$label, levels = unique(nodes$label))
nodes <- as_tibble(nodes)
# prepare data for edges
edges <- as_tibble(edgelist)
net.tidy <- tbl_graph(nodes = nodes, edges = edges, directed = TRUE, node_key = "label")
ggraph(net.tidy, layout = "linear") +
geom_edge_arc(alpha = 0.5) +
scale_edge_width(range = c(0.2, 2)) +
scale_colour_manual(values= vrtxc) +
geom_node_point(aes(size = degrees, color = family)) +
geom_node_text(aes(label = elec), angle = 90, hjust = 1, nudge_y = -0.5, size = 3) +
coord_cartesian(clip = "off") +
theme_graph()+
theme(legend.position = "top")
我得到了一张我喜欢的很棒的图表。
不过,我想把两组电极分开,在中间,Oz所在的地方,一点点,看看有没有区别。在节点属性中,我将它们按组 (1,2) 区分,我想知道此信息是否可用于通过 x 轴扩展两组顶点,在左侧的一组 25 个电极上,另一个一个在轴的右边,在中间留下一个 space。
我附上一些数据以防有用
> nodes
# A tibble: 50 x 6
group degrees family label fill id
<fct> <dbl> <fct> <fct> <fct> <int>
1 1 5 fronp Fp1_1 #3B9AB2 1
2 1 9 fronp Fp2_1 #3B9AB2 2
3 1 6 fron F7_1 #5DAABC 3
4 1 7 fron F3_1 #5DAABC 4
5 1 11 fron Fz_1 #5DAABC 5
6 1 9 fron F4_1 #5DAABC 6
7 1 11 fron F8_1 #5DAABC 7
8 1 8 fronc FC5_1 #88BAAE 8
9 1 6 fronc FC1_1 #88BAAE 9
10 1 4 fronc FC2_1 #88BAAE 10
# … with 40 more rows
万一有人感兴趣,我最后在 nodes
数据框中插入了一些虚拟行,它成功了。
我使用以下代码通过两个不同的电极得到了一张很棒的图表:
elec <- c("Fp1","Fp2","F7","F3","Fz","F4","F8","FC5","FC1","FC2","FC6","C3","Cz","C4","CP5","CP1","CP2","CP6","P7","P3","Pz","P4","P8","POz","Oz",
"Fp1","Fp2","F7","F3","Fz","F4","F8","FC5","FC1","FC2","FC6","C3","Cz","C4","CP5","CP1","CP2","CP6","P7","P3","Pz","P4","P8","POz","Oz")
edgelist <- get.edgelist(net)
# get vertex labels
label <- get.vertex.attribute(net, "name")
# get vertex groups
group <- get.vertex.attribute(net, "group")
# get vertex fill color
fill <- get.vertex.attribute(net, "color")
# get family
family <- get.vertex.attribute(net, "family")
# get vertex degree
degrees <- degree(net)
# data frame with groups, degree, labels and id
nodes <- data.frame(group, degrees, family, label, fill, id=1:vcount(net))
nodes$family <- factor(nodes$family, levels = unique(nodes$family))
nodes$label <- factor(nodes$label, levels = unique(nodes$label))
nodes <- as_tibble(nodes)
# prepare data for edges
edges <- as_tibble(edgelist)
net.tidy <- tbl_graph(nodes = nodes, edges = edges, directed = TRUE, node_key = "label")
ggraph(net.tidy, layout = "linear") +
geom_edge_arc(alpha = 0.5) +
scale_edge_width(range = c(0.2, 2)) +
scale_colour_manual(values= vrtxc) +
geom_node_point(aes(size = degrees, color = family)) +
geom_node_text(aes(label = elec), angle = 90, hjust = 1, nudge_y = -0.5, size = 3) +
coord_cartesian(clip = "off") +
theme_graph()+
theme(legend.position = "top")
我得到了一张我喜欢的很棒的图表。
不过,我想把两组电极分开,在中间,Oz所在的地方,一点点,看看有没有区别。在节点属性中,我将它们按组 (1,2) 区分,我想知道此信息是否可用于通过 x 轴扩展两组顶点,在左侧的一组 25 个电极上,另一个一个在轴的右边,在中间留下一个 space。
我附上一些数据以防有用
> nodes
# A tibble: 50 x 6
group degrees family label fill id
<fct> <dbl> <fct> <fct> <fct> <int>
1 1 5 fronp Fp1_1 #3B9AB2 1
2 1 9 fronp Fp2_1 #3B9AB2 2
3 1 6 fron F7_1 #5DAABC 3
4 1 7 fron F3_1 #5DAABC 4
5 1 11 fron Fz_1 #5DAABC 5
6 1 9 fron F4_1 #5DAABC 6
7 1 11 fron F8_1 #5DAABC 7
8 1 8 fronc FC5_1 #88BAAE 8
9 1 6 fronc FC1_1 #88BAAE 9
10 1 4 fronc FC2_1 #88BAAE 10
# … with 40 more rows
万一有人感兴趣,我最后在 nodes
数据框中插入了一些虚拟行,它成功了。