bioconductor v3.9.0 Rgraphviz
Interfaces R with the AT and T graphviz library for
Link to this section Summary
Functions
Class "AgEdge": A class to describe an edge for a Ragraph object
Class "AgNode": A class to describe a node for a Ragraph object
Class "AgTextLabel": Represents a graphviz text label
Class "BezierCurve": A class to describe a Bezier curve
Graph Attributes for Rgraphviz
Graphviz Layout Methods
Class "Ragraph": A class to handle libgraph representations
A function to obtain a libgraph object
A function to obtain a Ragraph object
Read / write Ragraph objects
Class "boundingBox": A class to describe the bounding box of a Ragraph
A function to build lists of node and edge objects
Get and set attributes for a cluster of an Ragraph object
Functions to generate and check global attribute lists
Get and set default attributes for an Ragraph
Get and set attributes of an Ragraph object
A function to layout graph locations
List capabilities of Graphviz
A function to determine graphviz library version
A function to compute layouts of graph objects
make a list of character vectors that can be used as a value for the nodeAttrs argument in agopen
Class "pEdge": A class to represent an edge
Class "pNode": A class to plot nodes
A function to plot pie graphs as a glyph
Plot a graph object - methods
A Function To List Removed Edges
Render a laid out graph object
A Generic For Converting Objects To Dot
Render a graph in a file with given format
Class "xyPoint": A class to represent a X/Y coordinate.
Link to this section Functions
AgEdge_class()
Class "AgEdge": A class to describe an edge for a Ragraph object
Description
This class is used to represent edges for the
Ragraph
class. One can retrieve various pieces of information
as well as draw them.
Seealso
Ragraph
, BezierCurve
, xyPoint
Author
Jeff Gentry
Examples
V <- letters[1:10]
M <- 1:4
g1 <- randomGraph(V, M, .2)
z <- agopen(g1,name="foo")
x <- AgEdge(z) ## list of AgEdge objects
vv <- x[[1]]
vv
## Demonstrate the methods of this class
splines(vv)
sp(vv)
ep(vv)
numSplines(vv)
getSpline(vv, 1)
head(vv)
tail(vv)
txtLabel(vv)
arrowhead(vv)
arrowtail(vv)
arrowsize(vv)
AgNode_class()
Class "AgNode": A class to describe a node for a Ragraph object
Description
This class is used to represent nodes for the
Ragraph
class. One can retrieve various pieces of information
as well as draw them.
Seealso
Author
Jeff Gentry
Examples
V <- letters[1:10]
M <- 1:4
g1 <- randomGraph(V, M, .2)
z <- agopen(g1,name="foo")
x <- AgNode(z) ## list of AgNode objects
vv <- x[[1]]
## The methods in use
color(vv)
fillcolor(vv)
getNodeCenter(vv)
getNodeXY(vv)
getNodeHeight(vv)
getNodeLW(vv)
getNodeRW(vv)
name(vv)
shape(vv)
style(vv)
txtLabel(vv)
AgTextLabel_class()
Class "AgTextLabel": Represents a graphviz text label
Description
This class is used to represent the textlabel object in C from the Graphviz library
Seealso
Author
Jeff Gentry
Examples
V <- letters[1:10]
M <- 1:4
g1 <- randomGraph(V, M, .2)
## Make the labels be the edge weights. This code is from the vignette
eAttrs <- list()
ew <- edgeWeights(g1)
lw <- unlist(unlist(ew))
toRemove <- removedEdges(g1)
lw <- lw[-toRemove]
names(lw) <- edgeNames(g1)
eAttrs$label <- lw
z <- agopen(g1,"foo", edgeAttrs=eAttrs)
x <- AgEdge(z) ## list of AgEdge objects
x[[1]] ## AgEdge
a <- txtLabel(x[[1]])
a ## txtLabel object
labelText(a)
labelLoc(a)
labelJust(a)
labelWidth(a)
labelColor(a)
labelFontsize(a)
BezierCurve_class()
Class "BezierCurve": A class to describe a Bezier curve
Description
This class is used to represent a Bezier curve in R, which can then be used for other applications, plotted, etc
Seealso
Author
Jeff Gentry
Examples
V <- letters[1:10]
M <- 1:4
g1 <- randomGraph(V, M, .2)
z <- agopen(g1,"foo")
x <- AgEdge(z) ## list of AgEdge objects
x[[1]] ## AgEdge
a <- splines(x[[1]])[[1]]
a ## BezierCurve
cPoints(a)
pointList(a)
bezierPoints(a)
GraphvizAttributes()
Graph Attributes for Rgraphviz
Description
The following describes the allowable attributes to be used with Rgraphviz. Most of these are sent directly to Graphviz and will influence the plot layout, some of these are only cosmetic and stay in R. Users are referred to the Graphviz web documentation which contains some more detailed information on these attributes (and is our source).
Seealso
plot.graph
, agopen
, GraphvizLayouts
Author
Jeff Gentry
References
http://www.graphviz.org/pub/scm/graphviz2/doc/info/attrs.html
GraphvizLayouts()
Graphviz Layout Methods
Description
The following describes the different layout methods that can be used
within Rgraphviz. Each layout method has its own particular
advantages and disadvantages and can have its own quirks. Currently
Rgraphviz supports three different layout methods: dot
,
twopi
and neato
.
Details
Portions of the layout descriptions were taken from documents provided
at http://www.research.att.com/sw/graphviz . The specific
documents are listed in the references
section of this page.
Seealso
GraphvizAttributes
, plot.graph
,
agopen
Author
Jeff Gentry
References
http://www.research.att.com/sw/tools/graphviz/dotguide.pdf , http://www.research.att.com/sw/tools/graphviz/neatoguide.pdf , http://www.research.att.com/sw/tools/graphviz/libguide.pdf
Examples
set.seed(123)
V <- letters[1:10]
M <- 1:4
g1 <- randomGraph(V, M, .2)
if (interactive()) {
op <- par()
on.exit(par=op)
par(ask=TRUE)
plot(g1, "dot")
plot(g1, "neato")
plot(g1, "twopi")
}
Ragraph_class()
Class "Ragraph": A class to handle libgraph representations
Description
Class Ragraph
is used to handle libgraph
representations of R graph objects.
Seealso
Author
Jeff Gentry and Li Long li.long@isb-sib.ch
Examples
set.seed(123)
V <- letters[1:10]
M <- 1:4
g1 <- randomGraph(V, M, .2)
z <- agopen(g1,"foo")
z
## The various methods in action
## These methods are all used to obtain positional information about nodes
getNodeXY(z)
getNodeHeight(z)
getNodeLW(z)
getNodeRW(z)
## Retrieve information about the edges in the graph
edgeNames(z)
edgemode(z)
## These get information about the layout
laidout(z)
layoutType(z)
boundBox(z)
## Used to retrieve the entire list of edges or nodes
AgEdge(z)
AgNode(z)
agopen()
A function to obtain a libgraph object
Description
This function will read in a graph
object and create a
Ragraph
object, returning it for use in other functions. The
graph represented by the Ragraph
can be laidout in various formats.
Usage
agopen(graph, name, nodes, edges, kind = NULL, layout = TRUE,
layoutType = "dot",
attrs = list(), nodeAttrs = list(), edgeAttrs = list(),
subGList = list(), edgeMode = edgemode(graph),
recipEdges=c("combined", "distinct"))
Arguments
Argument | Description |
---|---|
graph | An object of class graphNEL |
nodes | A list of pNode objects |
edges | A list of pEdge objects |
name | The name of the graph |
kind | The type of graph |
layout | Whether to layout the graph or not |
layoutType | Defines the layout engine. Defaults to dot, and see graphvizCapabilities()$layoutTypes for possible values. |
attrs | A list of graphviz attributes |
nodeAttrs | A list of specific node attributes |
edgeAttrs | A list of specific edge attributes |
subGList | A list describing subgraphs for the graph parameter |
edgeMode | Whether the graph is directed or undirected |
recipEdges | How to handle reciprocated edges, defaults to combined |
Details
graph
is from the package graph-class
.
The user can specify either the graph
parameter and/or a
combination of nodes
and edges
. If either of the latter
parameters are not specified then graph
must be passed in, and
is used in the functions buildNodeList
and
buildEdgeList
(as appropriate - if nodes
is
passed in but edges
is not, only buildEdgeList
is
called) which are default transformer functions to
generate the pNode
and pEdge
lists for layout.
The edgeMode
argument specifies whether the graph is to be laid
out with directed or undirected edges. This parameter defaults to the
edgemode of the graph
argument - note that if graph
was
not passed in then edgeMode
must be supplied.
The kind parameter works as follows: list(" ", " ", list(list("NULL:"), list("Determine the direction of the graph from the ", list("graph"), " ", " object. This is the default and the recommended method.")), " ", " ", list(list("AGRAPH:"), list("An undirected graph")), " ", " ", list(list("AGDIGRAPH:"), list("A directed graph")), " ", " ", list(list("AGRAPHSTRICT:"), list("A strict undirected graph")), " ", " ", list(list("AGDIGRAPHSTRICT:"), list("A strict directed graph")), " ", " ") Strict graphs do not allow self arcs or multi-edges.
If layout
is set to TRUE
, then the libgraph
routines are used to compute the layout locations for the graph.
Otherwise the graph is returned without layout information.
The subGList
parameter is a list describing any subgraphs,
where each element represents a subgraph and is itself a list with up
to three elements. The first element, graph
is required and
contains the actual graph
object for the subgraph. The second
element, cluster
is a logical value indicating if this is a
cluster
or a subgraph
(a value of TRUE
indicates
a cluster, which is also the default value if this element is not
specified). In Graphviz, subgraphs are more of an organizational
mechanism, whereas clusters are laid out separately from the main
graph and then later inserted. The last element of the list,
attrs
is used if there are any attributes for this subgraph.
This is a named vector where the names are the attributes and the
elements are the values for those attributes.
For a description of attrs
, nodeAttrs
and
edgeAttrs
, see the Ragraph
man page.
The recipEdges
argument can be used to specify how to handle
reciprocal edges. The default value, combined
will combine any
reciprocated edges into a single edge (and if the graph is directed,
will by default place an arrowhead on both ends of the edge), while
the other option is distinct
which will draw to separate
edges. Note that in the case of an undirected graph, every edge of a
graphNEL
is going to be reciprocal due to implementation issues.
Value
An object of class Ragraph
Seealso
graphLayout
,
Ragraph
, plot
Author
Jeff Gentry
References
http://www.research.att.com/sw/tools/graphviz/
Examples
set.seed(123)
V <- letters[1:10]
M <- 1:4
g1 <- randomGraph(V, M, .2)
z <- agopen(g1,name="foo")
z
z <- agopen(g1,name="foo",layoutType="neato")
agopenSimple()
A function to obtain a Ragraph object
Description
This function will read in a graphNEL
object and create a
Ragraph
object, returning it for use in other functions. The
graph represented by the Ragraph
can be laidout in various formats.
Usage
agopenSimple(graph, name, kind = NULL, edgeMode=edgemode(graph),
subGList=list(), recipEdges=c("combined", "distinct"))
Arguments
Argument | Description |
---|---|
graph | An object of class graphNEL |
name | The name of the Ragraph |
kind | The type of graph |
subGList | A list describing subgraphs for the graph parameter |
edgeMode | Whether the graph is directed or undirected |
recipEdges | How to handle reciprocated edges, defaults to combined , TODO: use this |
Details
graph
is from the package graph-class
.
The edgeMode
argument specifies whether the graph is to be laid
out with directed or undirected edges. This parameter defaults to the
edgemode of the graph
argument.
The kind parameter works as follows: list(" ", " ", list(list("NULL:"), list("Determine the direction of the graph from the ", list("graph"), " ", " object. This is the default and the recommended method.")), " ", " ", list(list("AGRAPH:"), list("An undirected graph")), " ", " ", list(list("AGDIGRAPH:"), list("A directed graph")), " ", " ", list(list("AGRAPHSTRICT:"), list("A strict undirected graph")), " ", " ", list(list("AGDIGRAPHSTRICT:"), list("A strict directed graph")), " ", " ") Strict graphs do not allow self arcs or multi-edges.
The subGList
parameter is a list describing any subgraphs,
where each element represents a subgraph and is itself a list with up
to three elements. The first element, graph
is required and
contains the actual graph
object for the subgraph. The second
element, cluster
is a logical value indicating if this is a
cluster
or a subgraph
(a value of TRUE
indicates
a cluster, which is also the default value if this element is not
specified). In Graphviz, subgraphs are more of an organizational
mechanism, whereas clusters are laid out separately from the main
graph and then later inserted. The last element of the list,
attrs
is used if there are any attributes for this subgraph.
This is a named vector where the names are the attributes and the
elements are the values for those attributes.
The recipEdges
argument can be used to specify how to handle
reciprocal edges. The default value, combined
will combine any
reciprocated edges into a single edge (and if the graph is directed,
will by default place an arrowhead on both ends of the edge), while
the other option is distinct
which will draw to separate
edges. Note that in the case of an undirected graph, every edge of a
graphNEL
is going to be reciprocal due to implementation issues.
Value
An object of class Ragraph
Seealso
graphLayout
,
Ragraph
, plot
Author
Li Long li.long@isb-sib.ch
References
http://www.research.att.com/sw/tools/graphviz/
Examples
set.seed(123)
V <- letters[1:10]
M <- 1:4
g1 <- randomGraph(V, M, .2)
z <- agopenSimple(g1,name="foo")
if(graphvizVersion() >= "2.10") {
## This example will only run with Graphviz >= 2.10
plot(z, "twopi")
}
agwrite()
Read / write Ragraph objects
Description
These functions will write an Ragraph
object to or from a file.
Usage
agwrite(graph, filename)
agread(filename, layoutType="dot", layout=TRUE)
Arguments
Argument | Description |
---|---|
graph | An object of class Ragraph |
filename | The input or output filename |
layoutType | character(1) specifying the format of the input file. must be one of graphvizCapabilities()$layoutTypes . |
layout | logical(1) indicating whether graphLayout is to be called on the result of file input. |
Details
These function are wrappers to agwrite() and agread() calls in Graphviz.
Seealso
Author
Jeff Gentry
Examples
V <- letters[1:10]
M <- 1:4
g1 <- randomGraph(V, M, .2)
z <- agopen(g1, "foo", layout=FALSE) ## default layoutType 'dot'
file <- tempfile()
agwrite(z, file)
## supported input types
graphvizCapabilities()$layoutTypes
g2 <- agread(file, layout=TRUE)
if (interactive())
plot(g2)
boundingBox_class()
Class "boundingBox": A class to describe the bounding box of a Ragraph
Description
The boundingBox
class is used to describe the
dimensons of the bounding box for a laid out Ragraph
Seealso
Author
Jeff Gentry
Examples
V <- letters[1:10]
M <- 1:4
g1 <- randomGraph(V, M, .2)
z <- agopen(g1,"foo")
x <- boundBox(z)
x
botLeft(x)
upRight(x)
buildNodeList()
A function to build lists of node and edge objects
Description
These functions can be used to generate lists of pNode
and
pEdge
objects from an object of class graph
. These
lists can then be sent to Graphviz to initialize and layout the graph
for plotting.
Usage
buildNodeList(graph, nodeAttrs = list(), subGList=list(), defAttrs=list())
buildEdgeList(graph, recipEdges=c("combined", "distinct"),
edgeAttrs = list(), subGList=list(), defAttrs=list())
Arguments
Argument | Description |
---|---|
graph | An object of class graph |
nodeAttrs | A list of attributes for specific nodes |
edgeAttrs | A list of attributes for specific edges |
subGList | A list of any subgraphs to be used in Graphviz |
recipEdges | How to deal with reciprocated edges |
defAttrs | A list of attributes used to specify defaults. |
Details
These functions will take either the nodes or the edges of the
specified graph and generate a list of either pNode
or
pEdge
objects.
The recipEdges
argument can be used to specify how to handle
reciprocal edges. The default value, combined
will combine any
reciprocated edges into a single edge (and if the graph is directed,
will by default place an arrowhead on both ends of the edge), while
the other option is distinct
which will draw to separate
edges. Note that in the case of an undirected graph, every edge of a
graphNEL
is going to be reciprocal due to implementation issues.
The nodeAttrs
and edgeAttrs
attribute lists are to be
used for cases where one wants to set an attribute on a node or an
edge that is not the default. In both cases, these are lists with the
names of the elements corresponding to a particular attribute and the
elements containing a named vector - the names of the vector are names
of either node or edge objects and the values in the vector are the
values for this attribute.
Note that with the edgeAttrs
list, the name of the edges are in
a particular format where an edge between x and y is named x~y
.
Note that even in an undirected graph that x~y
is not the same
as y~x
- the name must be in the same order that the edge was
defined as having.
The subGraph
argument can be used to specify a list of
subgraphs that one wants to use for this plot. The buildXXXList
functions will determine if a particular node or edge is in one of the
subgraphs and note that in the object.
The defAttrs
list is a list used to specify any default values
that one wishes to use. The element names corresponde to the
attribute and the value is the default for that particular attribute.
If there is no default specified in defAttrs
for an attribute
declared in nodeAttrs
or edgeAttrs
, then the latter must
have a value for every node or edge in the graph. Otherwise, if a
default is supplied, that value is used for any node or edge not
explicitly defined for a particular attribute.
Value
A list of class pNode
or pEdge
objects.
Seealso
agopen
, plot.graph
,
pNode
, pEdge
Author
Jeff Gentry
Examples
set.seed(123)
V <- letters[1:10]
M <- 1:4
g1 <- randomGraph(V, M, .2)
z <- buildEdgeList(g1)
x <- buildNodeList(g1)
clusterData_methods()
Get and set attributes for a cluster of an Ragraph object
Description
Attributes of a graph can be accessed using clusterData
.
There's no default attributes for clusters.
The attributes must be defined using graphDataDefaults
.
Usage
clusterData(self, cluster, attr)
clusterData(self, cluster, attr) <- value
Arguments
Argument | Description |
---|---|
self | A Ragraph-class instance |
cluster | cluster number |
attr | A character vector of length one specifying the name of a cluster attribute |
value | A character vector to store as the attribute value |
Author
Li Long li.long@isb-sib.ch
Examples
g1_gz <- gzfile(system.file("GXL/graphExample-01.gxl.gz",
package="graph"))
g11_gz <- gzfile(system.file("GXL/graphExample-11.gxl.gz",
package="graph"))
if(require(XML)) {
g1 <- fromGXL(g1_gz)
g11 <- fromGXL(g11_gz)
g1_11 <- join(g1, g11)
sgl <- vector(mode="list", length=2)
sgl[[1]] <- list(graph=g1, cluster=TRUE)
sgl[[2]] <- list(graph=g11, cluster=TRUE)
ng <- agopenSimple(g1_11, "tmpsg", subGList=sgl)
clusterData(ng, 1, c("bgcolor")) <- c("blue")
clusterData(ng, 2, c("bgcolor")) <- c("red")
toFile(ng, layoutType="dot", filename="g1_11_dot.ps", fileType="ps")
}
getDefaultAttrs()
Functions to generate and check global attribute lists
Description
The getDefaultAttrs
function can be used to generate a default
global attribute list for Graphviz. The checkAttrs
function
can be used to verify that such a list is valid for use.
Usage
getDefaultAttrs(curAttrs = list(), layoutType = "dot")
checkAttrs(attrs)
Arguments
Argument | Description |
---|---|
curAttrs | Any attributes currently defined |
layoutType | The layout method being used. Defaults to dot, and see graphvizCapabilities()$layoutTypes for possible values. |
attrs | An attribute list of graphviz attributes |
Details
The getDefaultAttrs
function generates a four element list
(elements being graph , cluster , node and
edge ). Contained in each is another list where the element
names correspond to attributes and the value is the value for that
attribute. This list can be used to set global attributes in
Graphviz, and the exact list returned by getDefaultAttrs
represents the values that are used as basic defaults.
The checkAttrs
function can be used to verify that a global
attribute list is properly formed.
Seealso
Author
Jeff Gentry
Examples
z <- getDefaultAttrs()
checkAttrs(z)
graphDataDefaults_methods()
Get and set default attributes for an Ragraph
Description
Get/Set default values for attributes associated with a graph.
Usage
graphDataDefaults(self)
graphDataDefaults(self, attr) <- value
Arguments
Argument | Description |
---|---|
self | A Ragraph-class instance |
attr | A character value giving the name of the attribute |
value | A character value as the default value for the specified attribute |
Author
Li Long li.long@isb-sib.ch
graphData_methods()
Get and set attributes of an Ragraph object
Description
Attributes of a graph can be accessed using graphData
.
The attributes could be defined using graphDataDefaults
.
Usage
graphData(self, attr)
graphData(self, attr) <- value
Arguments
Argument | Description |
---|---|
self | A Ragraph-class instance |
attr | A character vector of length one specifying the name of a graph attribute |
value | A character vector to store as the attribute values |
Author
Li Long li.long@isb-sib.ch
graphLayout()
A function to layout graph locations
Description
This function will take an object of class Ragraph
and will
perform a libgraph layout on the graph locations.
Usage
graphLayout(graph, layoutType=graph@layoutType)
Arguments
Argument | Description |
---|---|
graph | An object of type Ragraph |
layoutType | layout algorithm to use |
Details
If the graph has already been laid out, this function merely returns its parameter. Otherwise, it will perform a libgraph layout and retrieve the appropriate location information.
Value
A laid out object of type Ragraph
.
Seealso
Author
Jeff Gentry
Examples
V <- letters[1:10]
M <- 1:4
g1 <- randomGraph(V, M, .2)
z <- agopen(g1,"foo",layout=FALSE)
x <- z
a <- graphLayout(z)
graphvizCapabilities()
List capabilities of Graphviz
Description
List the capabilities of the installed Graphviz.
Usage
graphvizCapabilities()
Value
A list of 5 character vectors. Each character vector describes the relevant capabilitis of Graphviz.
Author
Kasper Daniel Hansen khansen@jhsph.edu
Examples
graphvizCapabilities()
graphvizVersion()
A function to determine graphviz library version
Description
This function will query the graphviz libraries that the package was built against and report what version of Graphviz is being used.
Usage
graphvizVersion()
Value
A list with three elements, two of class numeric_version
. The first
element named installed_version
represents the version of
Graphviz that is being used by the package. The second element named
build_version
represents the version of Graphviz that was used
to build the package. A mismatch between these two versions may
indicate problems. The third element is a logical named
bundled_graphviz
and indicates if Rgraphviz is using the
bundled Graphviz (default) or an external Graphviz.
Author
Jeff Gentry, modified by Kasper Daniel Hansen
Examples
graphvizVersion()
layoutGraph()
A function to compute layouts of graph objects
Description
This is a wrapper to layout graph objects using arbitrary layout engines. The default engine (and so far the only implemented engine) is ATT's Graphviz.
Usage
layoutGraph(x, layoutFun = layoutGraphviz, ...)
Arguments
Argument | Description |
---|---|
x | A graph object |
layoutFun | A function that performs the graph layout and returns a graph object with all necessary rendering information |
list() | Further arguments that are passed to layoutFun |
Details
Layout of a graph and its rendering are two separate
processes. layoutGraph
provides an API to use an arbitrary
algorithm for the layout. This is archived by abstraction of the
layout process into a separate function ( layoutFun
) with
well-defined inputs and outputs. The only requirements on the
layoutFun
are to accept a graph object as input and to return a
valid graph object with all the necessary rendering information stored
in its renderInfo
slot. This information comprises
list("for nodes:")
list("
", "
", " ", list(list("nodeX, nodeY"), list("the locations of the nodes, in the coordinate
", " system defined by ", list("bbox"), " (see below). ")), "
", "
", " ", list(list("lWidth, rWidth"), list("the width components of the nodes,
", " ", list("lWidth+rWidth=total width"), ". ")), "
", "
", " ", list(list("height"), list("the heights of the nodes. ")), "
", "
", " ", list(list("labelX, labelY"), list("node label locations. ")), "
", "
", " ",
list(list("labelJust"), list("the justification of the node labels. ")), "
", "
", " ", list(list("label"), list("node label text. ")), "
", "
", " ", list(list("shape"), list("the node shape. Valid values are ", list("box"), ",
", " ", list("rectangle"), ", ", list("ellipse"), ", ", list("plaintext"), ", ", list("circle"), "
", " and ", list("triangle"), ". ")), "
", "
", " ")
list("for edges:")
list("
", "
", " ", list(list("splines"), list("representation of the edge splines as a list of
", " ", list(list("BezierCurve")), " objects. ")), "
", "
", " ", list(list("labelX, labelY"), list("edge label locations. ")), "
", "
", " ", list(list("label"), list("edge label text. ")), "
", "
", " ", list(list("arrowhead, arrowtail"), list("some of Graphviz's arrow shapes are
", " supported. Currently they are: ", list("open"), ", ", list("normal"),
",
", " ", list("dot"), ", ", list("odot"), ", ", list("box"), ", ", list("obox"), ", ", list("tee"), ",
", " ", list("diamond"), ", ", list("odiamond"), " and ", list("none"), ". In addition, a
", " user-defined function can be passed which needs to be able to deal
", " with 4 arguments: A list of xy coordinates for the center of the
", " arrowhead, and the graphical parameters ", list("col"), ", ", list("lwd"), " and
", " ", list("lty"), ".")), "
", "
",
" ", list(list("direction"), list("The edge direction. The special value ", list("both"), " is
", " used when reciprocrated edges are to be collapsed. ")), " ", " ", " ")
To indicate that this information has been added to the graph, the
graph plotting function should also set the laidout flag in the
graphData
slot to TRUE
and add the bounding box
information (i.e., the coordinate system in which the graph is laid
out) in the format of a two-by-two matrix as item bbox
in the
graphData
slot.
AT&T's Graphviz
is the default layout algorithm to use when
layoutGraph
is called without a specific layoutFun
function. See agopen
for details about how to tweak
Graphviz
and the valid arguments that can be passed on through
list() . The most common ones to set in this context might be
layoutType
, which controls the type of layout to compute and
the nodeAttrs
and edgeAttrs
arguments, which control the
fine-tuning of nodes and edges.
Value
An object inheriting from class graph
Seealso
renderGraph
,
graph.par
,
nodeRenderInfo
,
edgeRenderInfo
,
agopen
,
Note
Please note that the layout needs to be recomputed whenever attributes
are changed which are bound to affect the position of nodes or
edges. This is for instance the case for the arrowhead
and
arrowtail
parameters.
Author
Florian Hahne, Deepayan Sarkar
Examples
set.seed(123)
V <- letters[1:5]
M <- 1:2
g1 <- randomGraph(V, M, 0.5)
edgemode(g1) <- "directed"
x <- layoutGraph(g1)
renderGraph(x)
## one of Graphviz's additional layout algorithms
x <- layoutGraph(g1, layoutType="neato")
renderGraph(x)
## some tweaks to Graphviz's node and edge attributes,
## including a user-defined arrowhead and node shape functions.
myArrows <- function(x, ...)
{
for(i in 1:4)
points(x,cex=i)
}
myNode <- function(x, col, fill, ...)
symbols(x=mean(x[,1]), y=mean(x[,2]), thermometers=cbind(.5, 1,
runif(1)), inches=0.5,
fg=col, bg=fill, add=TRUE)
eAtt <- list(arrowhead=c("a~b"=myArrows, "b~d"="odiamond", "d~e"="tee"))
nAtt <- list(shape=c(d="box", c="ellipse", a=myNode))
edgemode(g1) <- "directed"
x <- layoutGraph(g1, edgeAttrs=eAtt, nodeAttrs=nAtt, layoutType="neato")
renderGraph(x)
makeNodeAttrs()
make a list of character vectors that can be used as a value for the nodeAttrs argument in agopen
Description
make a list of character vectors that can be used as a value for the nodeAttrs argument in agopen
Usage
makeNodeAttrs(g, label = nodes(g), shape = "ellipse",
fillcolor = "#e0e0e0", ...)
Arguments
Argument | Description |
---|---|
g | graph |
label | character of length either 1 or numnodes(g) . If the length is 1 , the value is recycled. |
shape | character of length either 1 or numnodes(g) |
fillcolor | character of length either 1 or numnodes(g) |
... | further named arguments that are character vectors of length either 1 or numNodes(g) |
Details
This function is trivial but convenient.
Value
A list of named character vectors, each of which with
length numNodes(g)
.
Author
Wolfgang Huber huber@ebi.ac.uk
Examples
g <- randomEGraph(letters[1:10], p=0.2)
makeNodeAttrs(g)
pEdge_class()
Class "pEdge": A class to represent an edge
Description
This class is used to represent all necessary information to plot an edge in Graphviz
Details
The attrs
slot is a named list, where the names correspond to
attributes and the values in the list correspond to the value for that
element's attribute.
The subG
slot describes which subgraph this edge is a part of.
A value of 0
implies that the edge is not a member of any subgraph.
Seealso
pNode
, agopen
,
buildEdgeList
Author
R. Gentleman and Jeff Gentry
Examples
set.seed(123)
V <- letters[1:10]
M <- 1:4
g1 <- randomGraph(V, M, .2)
z <- buildEdgeList(g1)
vv <- z[[1]] ## Object of type pEdge
vv
from(vv)
to(vv)
pNode_class()
Class "pNode": A class to plot nodes
Description
This class is used to transfer information to Graphviz that is necessary to represent and plot a node.
Details
The attrs
slot is a named list, where the names correspond to
attributes and the values in the list correspond to the value for that
element's attribute.
The subG
slot describes which subgraph this node is a part of.
A value of 0
implies that the node is not a member of any subgraph.
Seealso
pEdge
, agopen
, buildNodeList
Author
R. Gentleman and Jeff Gentry
Examples
set.seed(123)
V <- letters[1:10]
M <- 1:4
g1 <- randomGraph(V, M, .2)
z <- buildNodeList(g1)
z[[1]] ## Object of type pNode
name(z[[1]])
pieGlyph()
A function to plot pie graphs as a glyph
Description
This function allows the user to plot a pie graph at a specified x/y location in a plotting region.
Usage
pieGlyph(x, xpos, ypos, labels = names(x), edges = 200, radius = 0.8, density = NULL, angle = 45, col = NULL, border = NULL, lty = NULL, main = NULL, ...)
Arguments
Argument | Description |
---|---|
xpos | The x location of the glyph |
ypos | The Y location of the glyph |
x | a vector of positive quantities. The values in x are displayed as the areas of pie slices. |
labels | a vector of character strings giving names for the slices. For empty or NA labels, no pointing line is drawn either. |
edges | the circular outline of the pie is approximated by a polygon with this many edges. |
radius | the pie is drawn centered in a square box whose sides range from $-1$ to $1$ . If the character strings labeling the slices are long it may be necessary to use a smaller radius. |
density | the density of shading lines, in lines per inch. The default value of NULL means that no shading lines are drawn. Non-positive values of density also inhibit the drawing of shading lines. |
angle | the slope of shading lines, given as an angle in degrees (counter-clockwise). |
col | a vector of colors to be used in filling or shading the slices. If missing a set of 6 pastel colours is used, unless density is specified when par("fg") is used. |
border, lty | (possibly vectors) arguments passed to polygon which draws each slice. |
main | an overall title for the plot. |
list() | graphical parameters can be given as arguments to pie . They will affect the main title and labels only. |
Seealso
Author
R. Gentleman, F. Sim
Examples
plot(1:10, col="white")
pieGlyph(1:20, 5, 5)
plot_methods()
Plot a graph object - methods
Description
A plot method for graph
objects.
Usage
list(list("plot"), list("graph,ANY"))(x, y, ..., name = "", subGList = list(),
attrs = list(), nodeAttrs = list(), edgeAttrs = list(),
recipEdges = c("combined", "distinct"))
list(list("plot"), list("Ragraph,ANY"))(x, y, edgeAttrs = list(), ..., main = NULL,
cex.main = NULL, col.main = "black", sub = NULL, cex.sub = NULL,
col.sub = "black", drawNode = drawAgNode, xlab, ylab, mai)
Arguments
Argument | Description |
---|---|
x | The graph object to plot |
y | The layout method to use: One of dot , neato , twopi , circo , and fdp . The default is dot |
name | The name of the graph, passed to agopen |
subGList | A list of subgraphs taken from the primary graph object to be plotted. If provided, these subgraphs will be clustered visually. If not provided, no clusters will be used. |
attrs | A list of Graphviz attributes to be sent to the layout engine |
nodeAttrs | A list of attributes for specific nodes |
edgeAttrs | A list of attributes for specific edges |
recipEdges | Determines how to draw reciprocating edges. See agopen |
main, cex.main, col.main | Main label and graphic parameters for the plot |
sub, cex.sub, col.sub | Subtitle and graphic parameters for the plot |
drawNode | Function to draw the nodes. The default is drawAgNode |
xlab | Label for the x axis of the plot |
ylab | Label for the y axis of the plot |
mai | Margins for plot |
... | General commands to be sent to plot |
Examples
# WHY DOES THIS NOT WORK IN CHECK?
# V <- letters[1:10]
# M <- 1:4
# g1 <- randomGraph(V, M, .2)
# plot(g1)
removedEdges()
A Function To List Removed Edges
Description
This function can be used to retrieve a numerical vector which will
describe which edges in a graph would be removed if recipEdges
is set to combined
during plotting.
Usage
removedEdges(graph)
Arguments
Argument | Description |
---|---|
graph | An object of class graph or Ragraph , the graph to perform this operation on |
Details
This function will simply detect which (if any) edges in a graph would be removed during combination of reciprocated edges.
Value
A numerical vector, where the values correspond to removed edges.
Seealso
edgeNames
,
agopen
, buildEdgeList
Author
Jeff Gentry
Examples
set.seed(123)
V <- letters[1:10]
M <- 1:4
g1 <- randomGraph(V, M, .2)
removedEdges(g1)
renderGraph()
Render a laid out graph object
Description
This method uses the renderInfo
slot of a graph object to
render it on a plotting device. The graph must have been laid out
using the layoutGraph
function before.
Usage
list(list("renderGraph"), list("graph"))(x, list(), drawNodes="renderNodes", drawEdges=renderEdges, graph.pars=list())
Arguments
Argument | Description |
---|---|
x | An object derived from class graph |
drawNodes | A function that is used for the node rendering. The details of its API are still undecided, so far the input to the function is the (laid out) graph object. Defaults to renderNodes , which is not exported in the name space (type Rgraphviz:::renderNodes to see the function definition). This default function knows how to draw node shapes of type box , rectangle , ellipse , plaintext , circle and triangle . In addition, an arbitrary user-defined function can be passed on to draw the node. This function needs to be able to deal with the following arguments: a two-by-two matrix of the bounding box for the respective node, and labelX , labelY , fill , col , lwd , lty , textCol , style , label and fontsize , which are all defined by the layout algorithm or are graphical nodeRenderInfo parameters. |
drawEdges | A function that is used for the edge rendering. Defaults to renderEdges . Currently, this function can draw different types of arrowheads: open , normal , dot , odot , box , obox , tee , diamond , odiamond and none . In addition, a user-defined function can be passed as arrowhead or arrowtail parameters which needs to be able to deal with 4 arguments: A list of xy coordinates for the center of the arrowhead, and the graphical parameters col , lwd and lty . |
graph.pars | A list of rendering parameters to use as defaults. Parameters that have been explicitely set using nodeRenderInfo , edgeRenderInfo or graphRenderInfo take precendence. If not explicitely supplied, the value of a call to graph.par is used. This design allows to set session-wide defaults. |
list() | further arguments |
Details
This method can render graph objects that have previously been laid
out using the function layoutGraph
. The details for user
defined node drawing remain to be decided.
Value
An object derived from class graph
with information about the
coordinates of the nodes in the coordinate system of the plotting
device added to the renderInfo
slot.
Seealso
layoutGraph
,
link[graph:renderInfo-class]{nodeRenderInfo}
,
link[graph:renderInfo-class]{edgeRenderInfo}
,
link[graph:renderInfo-class]{graphRenderInfo}
,
Author
Florian Hahne
Examples
set.seed(123)
V <- letters[1:5]
M <- 1:2
g1 <- randomGraph(V, M, 0.5)
edgemode(g1) <- "directed"
x <- layoutGraph(g1)
renderGraph(x)
## one of Graphviz's additional layout algorithms
x <- layoutGraph(g1, layoutType="neato")
renderGraph(x)
## some tweaks to Graphviz's node and edge attributes,
## including a user-defined arrowhead and node shape functions.
myArrows <- function(x, ...)
{
for(i in 1:4)
points(x,cex=i)
}
myNode <- function(x, col, fill, ...)
symbols(x=mean(x[,1]), y=mean(x[,2]), thermometers=cbind(.5, 1,
runif(1)), inches=0.5,
fg=col, bg=fill, add=TRUE)
eAtt <- list(arrowhead=c("a~b"=myArrows, "b~d"="odiamond", "d~e"="tee"))
nAtt <- list(shape=c(d="box", c="ellipse", a=myNode))
edgemode(g1) <- "directed"
x <- layoutGraph(g1, edgeAttrs=eAtt, nodeAttrs=nAtt, layoutType="neato")
renderGraph(x)
toDot_methods()
A Generic For Converting Objects To Dot
Description
This generic is used to convert objects of varying classes to the Dot
language. Currently, only the graph
class is supported.
Usage
toDot(graph, filename, ...)
Arguments
Argument | Description |
---|---|
graph | The graph to output to Dot |
filename | The name of the file to output to. |
list() | Any arguments to pass on to agopen |
Examples
set.seed(123)
V <- letters[1:10]
M <- 1:4
g1 <- randomGraph(V, M, .2)
nAttrs <- list()
eAttrs <- list()
nAttrs$label <- c(a="lab1", b="lab2", g="lab3", d="lab4")
eAttrs$label <- c("a~h"="test", "c~h"="test2")
nAttrs$color <- c(a="red", b="red", g="green", d="blue")
eAttrs$color <- c("a~d"="blue", "c~h"="purple")
toDot(g1, tempfile(), nodeAttrs=nAttrs, edgeAttrs=eAttrs)
toFile()
Render a graph in a file with given format
Description
Render a graph in a file with given format
Usage
toFile(graph, layoutType = "dot", filename, fileType = "dot")
Arguments
Argument | Description |
---|---|
graph | an instance of the Ragraph class |
layoutType | Which layout algorithm to use. Defaults to dot, and see graphvizCapabilities()$layoutTypes for possible values. |
filename | output file name |
fileType | Output file type. Defaults to dot , and see graphvizCapabilities()$deviceTypes for possible values. |
Details
This function takes a given Ragraph
, does the chosen layout, then
renders the output to an external file. Users could view the output file
with corresponding viewer.
Value
toFile
returns NULL after writing to a file.
Author
Li Long li.long@isb-sib.ch
References
Rgraphviz by E. Ganssner, S. North, www.graphviz.org
Examples
g1_gz <- gzfile(system.file("GXL/graphExample-01.gxl.gz",
package="graph"))
if(require(XML)) {
g1 <- fromGXL(g1_gz)
ag <- agopen(g1, name="test")
toFile(ag, layoutType="dot", filename="g1_dot.svg", fileType="svg")
toFile(ag, layoutType="neato", filename="g1_neato.ps", fileType="ps")
toFile(ag, layoutType="twopi", filename="g1_twopi.svg", fileType="svg")
}
xyPoint_class()
Class "xyPoint": A class to represent a X/Y coordinate.
Description
This class is used to describe a coordinate in 2-dimensional (X/Y) space
Author
Jeff Gentry
Examples
z <- new("xyPoint", x=150, y=30)
z
getPoints(z)
getX(z)
getY(z)