在Rgraphviz中使用图层

时间:2015-04-21 17:08:35

标签: r graphviz

在Rgraphviz中,如何将节点和边缘分配给特定图层,并仅绘制一个或多个选定图层?

在仔细阅读并搜索Rgraphviz文档之后,我想我已经弄清楚如何将节点和边缘分配给特定的图层 - 但我仍然无法弄清楚如何只绘制一个选定的图层。 / p>

This "How to use layers" item on the graphviz wiki意味着应该有一个" layerselect"图形属性,可用于仅绘制指定图层。但是,the list of allowed graph attributes in Rgraphviz不包括" layerselect。" "层"图形属性表示"只显示属于当前图层的那些组件,"但是我找不到关于如何设置(甚至查询)当前图层的信息。"

无论如何我试着这样做,但并不成功。这是我尝试的可重复的例子:

require('Rgraphviz')

params <- LETTERS[1:5] #nodes A, B, C, D, E
edgelist <- vector('list', #set up edges
                   length=length(params))
names(edgelist) <- params
edgelist[['B']] <- c('E','A') #add edges from B to E and from B to A
edgelist[['A']] <- 'C' #add edge from A to C
edgelist[['D']] <- 'E' #add edge from D to E
graph.nel <- new('graphNEL', #construct graphNEL object
                 nodes=params,
                 edgeL=edgelist,
                 edgemode='directed')

#I want there to be two layers: 
#"redlayer", containing nodes A, B, C, E and the edges between them;
#"blacklayer", containing node D and the edge from D to E.

#Assign the colors and layers of the edges
eAttr <- list(color=c('B~A'='red', 
                      'A~C'='red', 
                      'B~E'='red',
                      'D~E'='black'), 
              layer=c('B~A'='redlayer', 
                      'A~C'='redlayer', 
                      'B~E'='redlayer',
                      'D~E'='blacklayer')
)
#Assign the colors and layers of the nodes
nAttr <- list(color=c(B='red', 
                      A='red', 
                      C='red', 
                      E='red',
                      D='black'), 
              layer=c(B='redlayer',
                      A='redlayer',
                      C='redlayer',
                      E='redlayer',
                      D='blacklayer'))

#Now plot
plot(graph.nel, 
     attrs=list(graph=list(layers='redlayer:blacklayer', #Define the two layers
                           layersep=':', #Explicitly define the layer separation character
                           layerselect='redlayer')), #Attempt to select only the 'redlayer' for plotting
     edgeAttrs=eAttr, #specify edge attributes
     nodeAttrs=nAttr #specify node attributes
     ) 

以上代码的结果如下: Rgraphviz plot

但是,我预计只会出现红色的节点和边缘(即那些分配给名为&#39; redlayer&#39;的图层)!

我也试过

plot(graph.nel, 
         attrs=list(graph=list(layers='redlayer'), #Attempt to select only the 'redlayer' for plotting
         edgeAttrs=eAttr, #specify edge attributes
         nodeAttrs=nAttr #specify node attributes
         )

但它会产生完全相同的图 - 也就是说,两个图层仍然被绘制。

有没有办法只绘制名为&#39; redlayer&#39;的图层。在这个例子中?

0 个答案:

没有答案