2011-04-04 67 views
5

我从来没有在R中使用任何图形绘图包,我熟悉基本绘图命令和ggplot2包。我发现的(但还没有试用过)是Rgraphviznetworkigraph包。所以,我想问问你,这包有简单的学习曲线,满足下列要求:在R中绘制定向多图形

  • 拥有简单的布局引擎(春季布局,随机,...)
  • 试图得出两者之间的多条边顶点,以便它们不会重叠。作为奖励,它能很好地调整这一点。
  • 可以画循环。
  • 顶点和边缘标签,顶点和边的大小和颜色都可以调整。
  • (无需任何像链接分析,最短路径,最大流量等,但不错的图形算法,如果存在的话)

回答

3

igraph包似乎满足您的要求,与tkplot()功能帮助调整如果需要最终的布局。

下面是使用的例子:

s <- cbind(A=sample(letters[1:4], 100, replace=TRUE), 
      B=sample(letters[1:2], 100, replace=TRUE)) 
s.tab <- table(s[,1], s[,2]) 
library(igraph) 
s.g <- graph.incidence(s.tab, weighted=T) 
plot(s.g, layout=layout.circle, 
    vertex.label=c(letters[1:4],letters[2:1]),  
    vertex.color=c(rep("red",4),rep("blue",2)), 
    edge.width=c(s.tab)/3, vertex.size=20, 
    vertex.label.cex=3, vertex.label.color="white") 

enter image description here

使用交互式显示屏(有使用rgl 3D显示的可能性),它看起来像(我稍微移动一个顶点之后):

tkplot(s.g, layout=layout.circle, vertex.color=c(rep("red",4),rep("blue",2))) 

enter image description here

最后,您甚至可以将图表导出为最常见的格式,例如graphviz的dot

+0

感谢。当我需要再次绘制图表时,我会尝试igraph!仅仅为了一些信息,在我问了这个问题后,我和RGraphviz一起去了,并且通过重新编写我的原始任务,摆脱了绘制多边的需求。 – Timo 2011-05-02 13:06:12

+0

@Timo很高兴听到您用graphviz找到自己的方式。我也使用它很多。这只是'igraph'是最强大的,IMO。 (顺便说一句,我的+1给你的Q,当我回答时,我没有投票)---) – chl 2011-05-02 13:24:49

2

multigraph R软件包也很有用。对于上述示例bmgraph重复这样图表:

library("multigraph") 
bmgraph(s.tab, layout = "circ", pch = 16:16, pos = 0, vcol = 6:7, lwd = 3, cex = 9) 

enter image description here



而对于定向版本:

bmgraph(s.tab, "circ", pch = 16:16, pos = 0, vcol = 6:7, lwd = 3, cex = 9, directed = TRUE) 

enter image description here