请有人帮助如何使用以下信息绘制中介图。我尝试过Diagrammar + Graphviz,但无法在绘图上显示压力(1.00)、幸福感(0.62)和以上自尊(0.80)下的值。有谁知道 R 包可以重新创建如附件所示的路径图吗?
使用 ggraph 包可能会产生视觉上有吸引力的结果,并且颜色、文本、字体、箭头等也可以完全自定义。
library(tidygraph)
library(ggplot2)
library(ggraph)
nodes <- c("Self-esteem\n0.80", "a\n-0.42", "Stress\n1.00",
"c\n-0.32", "Wellbeing\n0.62", "b\n0.28")
data.frame(from = nodes, to = c(nodes[-1], nodes[1])) |>
as_tbl_graph() |>
mutate(x = c(0, -0.5, -1, 0, 1, 0.5),
y = 2 * sin(pi/3) * c(1, 0.5, 0, 0, 0, 0.5)) |>
ggraph(layout = "manual", x = x, y = y) +
geom_edge_link(aes(end_cap = circle(rep(c(0, 1.5), 3))),
arrow = arrow(length = unit(3, "mm"), type = "closed")) +
geom_node_circle(aes(r = rep(2:1/10, 3),
fill = factor(rep(2:1/10, 3)))) +
geom_node_text(aes(label = name)) +
scale_fill_manual(values = c("gray85", "white"), guide = "none") +
theme_graph() +
coord_equal()