ggraph弧形图剪辑标签文本。

问题描述 投票:1回答:1

我使用的是 igraphggraph 包来绘制弧形图。我在使用 geom_node_text 参数,因为随着文本标签长度的增加,图形下边距不会相应增加。所以,如果一个节点的标签有点长,最终会被从图上剪掉。

下面是一个可重复的例子,使用 karate 采样数据 igraphdata 包。

data(karate)
ggraph(karate, layout="linear")+
  geom_edge_arc(aes(edge_width=weight), edge_alpha=0.5, fold=T)+
  geom_node_point(aes(size=strength(karate), color=as.factor(color)))+
  geom_node_text(aes(label=name), angle=90, hjust=1, nudge_y = -0.2, size=4)+
  theme_void()+theme(legend.position = "none")

enter image description here

我已经尝试过通过 theme(plot.margin=) 但标签还是被剪掉了。

r ggplot2 igraph ggraph arc-diagram
1个回答
2
投票

你可以设置 coord_cartesian(clip = "off") 在你的剧情中,扩大剧情的边距。

data(karate)

ggraph(karate, layout = "linear") +
  geom_edge_arc(aes(edge_width = weight), edge_alpha = 0.5, fold = TRUE) +
  geom_node_point(aes(size = strength(karate), color = as.factor(color))) +
  geom_node_text(aes(label = name), angle = 90, hjust = 1, nudge_y = -0.2, size = 4) +   
  coord_cartesian(clip = "off") + 
  theme_void() +  
  theme(legend.position = "none", plot.margin = unit(rep(30, 4), "points"))

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.