Description Usage Arguments Details Value Author(s) See Also Examples
This function aids in drawing two directed graphNEL objects to have the same node layout but still preserving the edges. This is useful when comparing two graphs. The function also highlights the differences in the edges.
1 2 | combineAndDraw(g1, g2, col1 = "steelblue", col2 = "tomato", cols, size,
fontsize, name = "", ...)
|
g1 |
A graphNEL object |
g2 |
A graphNEL object |
col1 |
Edge color of edges unique to g1 |
col2 |
Edge color of edges unique to g2 |
cols |
Node colors. A named character vector of colors where the names are the node labels. If the length is 1 the color is reused. |
size |
A vector of node sizes. If the length is 1 the size is reused. |
fontsize |
A vector of the sizes of the node labels. If the length is 1 the given size is reused. |
name |
The name of the graphs. |
... |
Arguments passed to |
The function works by combining g1
and g2
and making
unique edges of g2
invisible in the merged graph and vice versa
for the unique edges of g1
.
A list
of length three with the laid out graphs. The first
and second entry is the laid out g1 and g2 with coloured unique edges.
The third element is the merged graph (rarely of particular interest).
Anders Ellern Bilgrau <anders.ellern.bilgrau (at) gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | if (require("gRbase") && require("graph") && require("Rgraphviz")) {
g1 <- dagList(list(~A|B, ~A|C, ~A|D, ~E, ~F|A, ~G, ~H|I, ~I|H,
~J|K, ~K|J, ~L|M, ~X|Y, ~Y|X))
g2 <- dagList(list(~A|B, ~C|A, ~D, ~A|E, ~F|A, ~I|H,
~J|K, ~K|J, ~L|M, ~M|L, ~W|V, ~V|W))
cc <- combineAndDraw(g1, g2)
col1 <- rep("steelblue", length(edgeNames(g1)))
names(col1) <- edgeNames(g1)
col2 <- rep("tomato", length(edgeNames(g2)))
names(col2) <- edgeNames(g2)
par(oma = c(0,0,0,0)+.4)
layout(rbind(c(1,1,2,2), c(0,3,3,0), c(4,4,5,5)))
plot(g1, edgeAttrs = list(color = col1), main = "Graph 1"); box()
plot(g2, edgeAttrs = list(color = col2), main = "Graph 2"); box()
plot(cc[[3]], main = "Merged graph"); box()
plot(cc[[1]], main = "Graph 1 (laid out as merged graph)"); box()
plot(cc[[2]], main = "Graph 2 (laid out as merged graph)"); box()
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.