fra*_*ure 1 visualization r igraph
我正在研究使用R和igraph在亚马逊上一起购买的政治书籍的可视化.我已经能够以一种形式获得网络图,这种形式揭示了某些书籍落入某个位置的方式,表明他们不仅仅是购买其他具有相同政治观点的书籍的人购买的.这是图表:

我的问题是,如果所有这些书都在更紧密的集群中,那么阅读标签是非常不可能的.如果我能够在不掩盖连接集群的少数标题的中间位置的情况下,我想扩展这些集群.
有没有人对我如何做到这一点有任何想法?
为了生成此图,我将此数据作为gml文件读入,然后执行以下操作:
g<-read.graph("data/polbooks/polbooks.gml", format=c("gml"))
V(g)$degree <- degree(g, mode="all")
cut.off <- mean(V(g)$degree)
sub <- induced_subgraph(g, which(V(g)$degree>cut.off))
plot(sub, vertex.shape="none", vertex.size=1,
vertex.label.color=ifelse(V(sub)$value=="l", "blue", "red"),
layout=layout_with_fr)
Run Code Online (Sandbox Code Playgroud)
我已经尝试了几种内置布局,但它们都没有真正产生预期的结果.
以下是我为提高图表的可读性而做的工作:
包装长书.
缩小字体大小.
设置种子以使布局可重现,允许您保留您喜欢的"随机"布局.
使用来自另一个SO答案的图形布局代码来增加节点分离.
这是实施:
## Function to wrap long strings
# Source: http://stackoverflow.com/a/7367534/496488
wrap_strings <- function(vector_of_strings,width){
as.character(sapply(vector_of_strings, FUN=function(x){
paste(strwrap(x, width=width), collapse="\n")
}))
}
# Apply the function to wrap the node labels
V(sub)$label = wrap_strings(V(sub)$label, 12)
## Shrink font
V(sub)$label.cex = 0.8
# Function to increase node separation (for explanatory details, see the link below)
# Source: http://stackoverflow.com/a/28722680/496488
layout.by.attr <- function(graph, wc, cluster.strength=1,layout=layout.auto) {
g <- graph.edgelist(get.edgelist(graph)) # create a lightweight copy of graph w/o the attributes.
E(g)$weight <- 1
attr <- cbind(id=1:vcount(g), val=wc)
g <- g + vertices(unique(attr[,2])) + igraph::edges(unlist(t(attr)), weight=cluster.strength)
l <- layout(g, weights=E(g)$weight)[1:vcount(graph),]
return(l)
}
## Make layout reproducible. Different values will produce different layouts,
## but setting a seed will allow you to reproduce a layout if you like it.
set.seed(3)
Run Code Online (Sandbox Code Playgroud)
现在让我们绘制图表:
plot(sub, vertex.shape="none", vertex.size=1,
vertex.label.color=ifelse(V(sub)$value=="l", "blue", "red"),
layout=layout.by.attr(sub, wc=1))
Run Code Online (Sandbox Code Playgroud)