在Rgraphviz中设置边宽度

在Rgraphviz中设置边宽度,r,graph,graphviz,R,Graph,Graphviz,显然,在Rgraphviz中设置边缘宽度是可能的,尽管没有很好的文档记录。以下是一种方法: library(graph) library(Rgraphviz) nodes <- c( LETTERS[1:3] ) edgesL <- list( A=c("B", "C"), B=c("A", "C"), C=c("B", "A" ) ) graph <- new( "graphNEL", nodes= nodes, edgemode="undirected", edgeL=ed

显然,在Rgraphviz中设置边缘宽度是可能的,尽管没有很好的文档记录。以下是一种方法:

library(graph)
library(Rgraphviz)
nodes <- c( LETTERS[1:3] )
edgesL <- list( A=c("B", "C"), B=c("A", "C"), C=c("B", "A" ) )
graph <- new( "graphNEL", nodes= nodes, edgemode="undirected", edgeL=edgesL )
rag <- agopen( graph, "" )
rag@AgEdge[[1]]@lwd <- 5
plot(rag)
但是,Ragraph手册页中根本没有提到“edgeAttrs”。我感到困惑和愤怒。绝望。绝望的人们研究源代码。显然,
agopen()
抛出一个错误,因为
getDefaultAttrs()
不知道lwd插槽。不过,我们可以修改它:

eAttrs <- list( lwd=list( "A~C"=5, "A~B"=1 ) )
rag <- agopen( graph, "", edgeAttrs=eAttrs, attrs= list(edge=list(lwd=2)) )
plot(rag)
它有用吗?哦,是的:

rag <- agopen( graph, "" )
rag <- setEdgeAttr( rag, "lwd", c(5, 20), c("B", "B"), c( "A", "C" ) )
plot(rag)

rag当我发现并能够修复我喜欢或依赖的软件包中的缺陷时,我通常会联系软件包维护人员,提出建议的修复/增强。在我看来,您有足够的技能来提供这种帮助,而且根据我的经验,维护人员总是乐于接受您愿意提供的任何增量改进。i、 不要生气,要乐于助人!嗯,首先我想知道这样一个旧包装是否真的有缺点,这是可以理解的。另外,希望我没有表现出居高临下或指责。只是你在这里发现的东西让我印象深刻,即使是在更古老的包装中,这种细节也可能在很长一段时间内被忽视。就在上周,我向运行良好的sp软件包提交了几个补丁,使用户可以选择传递颜色向量,以便在具有多个图层的地图中绘制多个多边形和线。
if (!is.null(edgeAttrs$lwd)) {
    for (i in seq(along = edgeAttrs$lwd)) {
        attr(attr(g, "AgEdge")[[i]], "lwd") <- edgeAttrs$lwd[i]
    }
}
 For a description of ‘attrs’, ‘nodeAttrs’ and ‘edgeAttrs’, see the
 ‘Ragraph’ man page.
eAttrs <- list( lwd=list( "A~C"=5, "A~B"=1 ) )
rag <- agopen( graph, "", edgeAttrs=eAttrs, attrs= list(edge=list(lwd=2)) )
plot(rag)
setEdgeAttr <- function( graph, attribute, value, ID1, ID2 ) {

  idfunc <- function(x) paste0( sort(x), collapse="~" )
  all.ids <- sapply( AgEdge(graph), 
    function(e) idfunc( c( attr(e, "head"), attr( e, "tail" ))))

  sel.ids <- apply(cbind( ID1, ID2 ), 1, idfunc )

  if(!all(sel.ids %in% all.ids)) stop( "only existing edges, please" )
  sel <- match( sel.ids, all.ids )

  for(i in 1:length(sel)) {
    attr( attr( graph, "AgEdge" )[[ sel[i] ]], attribute ) <- value[i]
  }

  return(graph)
}
rag <- agopen( graph, "" )
rag <- setEdgeAttr( rag, "lwd", c(5, 20), c("B", "B"), c( "A", "C" ) )
plot(rag)