小编use*_*755的帖子

使边缘指向 ggraph 中排斥的标签

我正在使用 ggraph R 包创建一个图表。我想使用 来标记所有节点geom_node_label(),但这通常会造成重叠。解决这个问题的一种方法是使用参数repel=TRUE。不幸的是,我似乎无法弄清楚如何使边缘指向标签已移动的位置。

解决这个问题的一种可能的方法可能是在制作图表之前进行排斥布局,但我也没有找到一种方法。

library(igraph)
library(ggraph)

# Create example graph
my_graph <- make_graph('Meredith')
V(my_graph)$Label <- 1:70


set.seed(2222) # reproducible layout
ggraph(my_graph) +
    geom_edge_link() +
    geom_node_label(aes(label = Label), repel=FALSE) +
    theme_graph()

# Graph with repel = TRUE
set.seed(2222)
ggraph(my_graph) +
    geom_edge_link() +
    geom_node_label(aes(label = Label), repel=TRUE) +
    theme_graph()
Run Code Online (Sandbox Code Playgroud)

以下是上述代码的绘图:

  • 地块 1:

在此输入图像描述

  • 情节2:

在此输入图像描述

r ggplot2 ggrepel ggraph

5
推荐指数
0
解决办法
670
查看次数

标签 统计

ggplot2 ×1

ggraph ×1

ggrepel ×1

r ×1