【发布时间】:2019-05-28 14:11:03
【问题描述】:
当我使用 ggraph 绘制带有节点标签的网络图时,标签经常被切断。
library(igraph)
library(ggraph)
#generate a sample network
tstGr <- erdos.renyi.game(6, 0.5, type=c("gnp", "gnm"), directed = TRUE, loops = FALSE)
#Assign labels to the nodes
V(tstGr)$name = c("LongName1", "LongName2", "LongName3", "LongName4", "LongName5", "LongName6")
#Plotting function
PfuncLite = function(Gr){
p = ggraph(Gr, layout = "circle")+
geom_edge_fan(color = "#971b2f", alpha = 0.5, arrow = arrow(ends = "last", length = unit(0.15, "inches")), start_cap = circle(6, 'mm'), end_cap = circle(6, 'mm')) +
geom_node_label(aes(label = V(Gr)$name), color = "#002f6c") +
theme_graph()+
ggtitle("Interaction Network")
return(p)
}
PlotTstGr = PfuncLite(tstGr)
PlotTstGr
如果我在 ggsave 中更改绘图的宽度,我最终可以获得足够宽的绘图以包含整个标签。
ggsave("TestPlot1.jpg", plot = PlotTstGr)
ggsave("TestPlot2.jpg", plot = PlotTstGr, width = 15)
然后拉伸输出图 TestPlot2.jpg。有没有办法防止节点标签被切断?我不知道问题出在 ggraph 还是 ggplot2。
【问题讨论】: