# 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:

### gridGraphviz (new)

``````>> dot -Tpng ex3.dot -o ex3.png
`````` ```# create Ragraph object
rag <- agopen(graph, "", attrs=list(node=list(shape="ellipse")))
```
```#plot
plot(rag)
``` ```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'
``` ```library(gridGraphviz)

# create Ragraph object
rag <- agopenTrue(graph, "", attrs=list(node=list(shape="ellipse")))
```
```#plot
grid.graph(rag)
``` ## Discussion

gridGraphviz (old) fails to produce ellipse shaped nodes.