2

我有一组节点/边缘文件来使用 ggnet2 生成网络。我面临两个问题:

  1. 有些可能只有 5-10 个节点,而另一些可能有 1000-10000 个节点,这使得情节过于拥挤。所以我很好奇是否有任何选项可以自动调整节点和标签大小。

  2. 虽然一些标签字符串很长(即 >20 个字符),但部分标签将超出图像。有没有办法避免这种情况?

代码如下

v = read.csv(vfile, sep="\t", na.string="nnn")
e = read.csv(efile, sep="\t", na.string="nnn")

# build the network
net = network(e, directed = TRUE, mode="hall")

# group affiliation
x = data.frame(Entity = network.vertex.names(net))
x = merge(x, v, by.x = 'Entity', by.y='ID', sort = FALSE)
net %v% "Group" = as.character(x$Group)

# color palette
y = RColorBrewer::brewer.pal(9, "Set2")[ c(1:length(levels(x$Group))) ]
names(y) = levels(x$Group)

# network plot
png(graphFile,width = 8, height = 6, units = 'in', res = 300)
ggnet2(
  net, color = "Group", palette = y,  
  node.size = 12,
  edge.size = 1, edge.alpha = 0.5,
  label = TRUE, label.size = 3, label.alpha = 0.8, 
  legend.size = 12, legend.position = "right",
  arrow.size=5, arrow.gap=0.01)
dev.off()
4

0 回答 0