【问题标题】:ggraph arc diagram clips label textggraph 弧形图剪辑标签文本
【发布时间】:2020-08-05 21:30:05
【问题描述】:

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

这是一个使用来自igraphdata 包的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")

我已经尝试通过theme(plot.margin=) 更改绘图边距,但标签还是被剪掉了。

【问题讨论】:

    标签: r ggplot2 igraph ggraph arc-diagram


    【解决方案1】:

    您可以在情节中设置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"))
    

    【讨论】:

      猜你喜欢
      • 2020-11-10
      • 2016-09-12
      • 1970-01-01
      • 1970-01-01
      • 2019-05-27
      • 1970-01-01
      • 2021-03-10
      • 2015-12-17
      • 2016-05-24
      相关资源
      最近更新 更多