Example 3: directed graph

A directed graph with four nodes and four edges.

Graph declaration

In all cases the graph is explicitly declared with ellipse shaped nodes. The dot file edges are declared in alphabetical order as this is the (assumed) default for how Rgraphviz will pass edges internally to graphviz.

Dot file for graphviz:


digraph {  
	node [shape=ellipse];	

        // declare nodes
        a b c d;
          
        // declare directed edges
        a -> b; 
        b -> c; 
        c -> d; 
        d -> a;
}
	  

R code for Rgraphviz and gridGraphviz:

# load Rgraphviz library
library(Rgraphviz)

# nodes
nodes <- c("a", "b", "c", "d")

# edges
edgeList <- list(a=list(edges=c("b")),
                 b=list(edges=c("c")),
                 c=list(edges=c("d")),
                 d=list(edges=c("a")))

# graph
graph <- new("graphNEL", nodes=nodes, edgeL=edgeList, edgemode="directed")

# Ragraph
rag3 <- agopen(graph, "", attrs=list(node=list(shape="ellipse")))

Graph rendering:

graphviz

Rgraphviz

gridGraphviz (old)

gridGraphviz (new)

>> dot -Tpng ex3.dot -o ex3.png
    
graphviz output
# create Ragraph object
rag <- agopen(graph, "", attrs=list(node=list(shape="ellipse")))
#plot  
plot(rag)
plot of chunk Rgraphviz-ex3
library(gridGraphviz)

# create Ragraph object
rag <- agopen(graph, "", attrs=list(node=list(shape="ellipse")))
#plot  
grid.graph(rag)
## Warning: Unsupported node shape; using 'box'
## Warning: Unsupported node shape; using 'box'
## Warning: Unsupported node shape; using 'box'
## Warning: Unsupported node shape; using 'box'
plot of chunk gridGraphviz-old-ex3
library(gridGraphviz)

# create Ragraph object
rag <- agopenTrue(graph, "", attrs=list(node=list(shape="ellipse")))
#plot  
grid.graph(rag)
plot of chunk gridGraphviz-new-ex3

Discussion

gridGraphviz (old) fails to produce ellipse shaped nodes.