简体   繁体   English

ggraph 弧形图剪辑 label 文本

[英]ggraph arc diagram clips label text

I am using the igraph and ggraph package to plot an arc diagram.我正在使用igraphggraph package 到 plot 弧形图。 I am having trouble with the geom_node_text parameter because, as the length of the text label increases, the graph lower margin will not increase accordingly.我遇到了geom_node_text参数的问题,因为随着文本 label 的长度增加,图形下边距不会相应增加。 So if the label for a node is a bit long, it ends up getting clipped off from the plot.因此,如果节点的 label 有点长,它最终会从 plot 中剪掉。

Here is a reproducible example using the karate sample data from the igraphdata package.这是一个使用来自igraphdata package 的karate样本数据的可重现示例。

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")

在此处输入图像描述

I have already tried to change the plot margins via the theme(plot.margin=) but the labels get clipped off anyway.我已经尝试通过theme(plot.margin=)更改 plot 边距,但无论如何标签都会被剪掉。

You can set coord_cartesian(clip = "off") in your plot and expand the plot margins:您可以在 plot 中设置coord_cartesian(clip = "off")并扩展 plot 边距:

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"))

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM