是的,你可以用width
aes
in most来做到这一点geom_edge_*
。此外,您可以使用scale_edge_width
根据加权变量微调最小/最大宽度。请参阅下面的两个示例。
此外,我认为这种美学存在问题ggforce
(它也给我带来了麻烦)。ggraph
确保您已更新到和的最新版本ggforce
。
library(ggraph)
library(igraph)
data=data.frame(w1=rep('like', 5),
w2 = c('apple', 'orange', 'pear','peach', 'banana'),
weight= c(2,3,5,8, 15))
第一个具有默认权重
data %>%
graph_from_data_frame() %>%
ggraph(layout = "fr") +
geom_edge_link(alpha = .25,
aes(width = weight)) +
geom_node_point(color = "blue", size = 2) +
geom_node_text(aes(label = name), repel = TRUE)+
theme_graph()+
labs(title = 'Graph with weighted edges',
subtitle = 'No scaling')
用于scale_edges_width
设置范围。注意 - scale_edges
* 可以接受多个参数。
data %>%
graph_from_data_frame() %>%
ggraph(layout = "fr") +
geom_edge_link(alpha = .25,
aes(width = weight)) +
geom_node_point(color = "blue", size = 2) +
geom_node_text(aes(label = name), repel = TRUE)+
scale_edge_width(range = c(1, 20))+ # control size
theme_graph()+
labs(title = 'Graph with weighted edges',
subtitle = 'Scaling add with scale_edge_width()')