当使用ggraph时,有没有一种方法可以加厚边缘颜色的图例线?我正在尝试覆盖,但无济于事。下面是一个例子:
library(tidyverse)
library(igraph)
library(ggraph)
set.seed(20190607)
#create dummy data
Nodes <- tibble(source = sample(letters, 8))
Edges <- Nodes %>%
mutate(target = source) %>%
expand.grid() %>%
#assign a random weight & color
mutate(weight = runif(nrow(.)),
color = sample(LETTERS[1:5], nrow(.), replace = TRUE)) %>%
#limit to a subset of all combinations
filter(target != source,
weight > 0.7)
#make the plot
Edges %>%
graph_from_data_frame(vertices = Nodes) %>%
ggraph(layout = "kk") +
#link width and color are dynamic
geom_edge_link(alpha = 0.5, aes(width = weight, color = color)) +
geom_node_point(size = 10) +
theme_graph() +
#don't need a legend for edge width, but the color override doesn't work
guides(edge_width = FALSE,
edge_color = guide_legend(override.aes = list(size = 2)))

我喜欢的输出看起来更像这样:

发布于 2019-06-08 00:34:00
我认为你真的想要调整width的美学,而不是size,所以这是一个小问题。
但棘手的部分(至少对我而言)是因为ggraph会自动扩展美学名称,例如width >>> edge_width,所以在尝试覆盖guide_legend()中的美学名称时,您需要使用edge_x格式。
所以你最终会得到这样的结果:
Edges %>%
graph_from_data_frame(vertices = Nodes) %>%
ggraph(layout = "kk") +
geom_edge_link(alpha = 0.5, aes(width = weight, edge_color = color)) +
geom_node_point(size = 10) +
theme_graph() +
guides(edge_color = guide_legend(override.aes = list(edge_width = 5)),
edge_width = F)

https://stackoverflow.com/questions/56496168
复制相似问题