tkplot {igraph} | R Documentation |
tkplot
and its companion functions serve as an
interactive graph drawing facility. Not all parameters of the plot can
be changed interactively right now though, eg. the colors of vertices,
edges, and also others have to be pre-defined.
tkplot (graph, layout = layout.random, layout.par = list(), labels = NULL, label.color = "darkblue", label.font = NULL, label.degree = -pi/4, label.dist = 0, vertex.color = "SkyBlue2", vertex.size = 15, edge.color = "darkgrey", edge.width = 1, edge.labels=NA, vertex.frame.color="black", ...) tkplot.close(tkp.id, window.close = TRUE) tkplot.off() tkplot.fit.to.screen(tkp.id, width = NULL, height = NULL) tkplot.reshape(tkp.id, newlayout, ...) tkplot.export.postscript(tkp.id) tkplot.getcoords(tkp.id, norm = FALSE) tkplot.center(tkp.id) tkplot.rotate(tkp.id, degree = NULL, rad = NULL)
graph |
The graph to plot. |
layout |
Either a function, or a character string or a numeric
matrix. It specifies how the vertices will be placed on the plot.
If it is a function, this function will be called with the graph and layout.param as parameters to determine the
actual coordinates.
If it is a character sting starting with “ a: ” then the
remaining part of the string specifies the name of the vertex
attribute to use as coordinates.
If it is a numeric matrix, then the matrix has to have one line for each vertex, specifying its coordinates. The matrix should have at least two columns, for the x and y coordinates, but it
can also have more (eg. for a future z coordinate).
|
layout.par |
A named list specifying the optional parameters of the layout
function, only used if the layout argument is a
function. The parameters themselves are layout function dependent,
they are discussed in the layout manual page.
|
labels |
Gives the labels to use for the vertices. It can be a
numeric or character vector. If NA the plot will have no
labels, if NULL numeric ids starting from one will be
used. If a character vector of length one with prefix
“a: ” is given then the corresponding vertex attribute
(without the “a: ” prefix) is used for the labels. |
label.color |
The color of the labels. If it is a character
scalar with prefix “a: ” then the corresponding vertex
attribute will be used. Otherwise if it is a vector of length one
then all labels will be the same color. It can also be a character
or numeric vector of the same length as the number of
vertices. Colors can be given as strings or integers, in the latter
case the actual color palette will be used. |
label.font |
The font for the labels, a tkfont object, by default 16pt Helvetica bold is used. |
label.degree |
Governs the placement of the vertex labels. 0
is right, pi/2 is down, pi is left. This argument can be a constant
(for all labels) or a numeric vector. If it is a constant string
with prefix “a: ” then the corresponding vertex
argument will be used. |
label.dist |
Numeric constant, gives the distance between the labels and the vertices. 1 is some “ideal” distance, based on the vertex and label sizes. Use 0 for drawing the labels on the vertices. |
vertex.color |
The color of the vertices, either a character
constant with prefix “a: ” for using an attribute or
without it: a constant color for all vertices, or a numeric or
character or numeric vector giving the different colors for the
vertices. |
vertex.size |
The size of the vertices. Either a numeric
constant, or a numeric vector, or a string with prefix
quote{a: } giving the vertex attribute to use. |
edge.color |
The color of the edges. Either a character vector
with prefix “a: ” naming the edge attribute to use or
one without it, or a numeric or character vector giving the colors
for each edge.
|
edge.width |
The width of the edges. Either a numeric constant or
a numeric vector, or a string with prefix “a: ” giving
the edge attribute to use. |
edge.labels |
Labels for the edges, this will be converted to a
character vector. The default is NA which suppresses edge
labels. The vector might contain NA 's as well to suppress
labels for some edges. |
vertex.frame.color |
The border color of the vertices,
either a character constant with prefix “a: ” for using
an attribute or without it: a constant color for all vertices, or a
numeric or character or numeric vector giving the different colors
for the vertices. |
tkp.id |
The id of the tkplot window to close. |
window.close |
Leave this on the default value. |
width |
The width of the rectangle for generating new coordinates. |
height |
The height of the rectangle for generating new coordinates. |
newlayout |
The new layout, see the layout parameter of
tkplot. |
norm |
Logical, should we norm the coordinates. |
degree |
The degree to rotate the plot. |
rad |
The degree to rotate the plot, in radian. |
... |
Not used right now. |
tkplot
is an interactive graph drawing facility. It is not very
well developed at this stage, but it should be still useful.
It's hangling should be quite straightforward most of the time, here are some remarks and hints.
There are different popup menus, activated by the right mouse button, for vertices and edges. Both operate on the current selection if the vertex/edge under the cursor is part of the selection and operate on the vertex/edge under the cursor if it is not.
One selection can be active at a time, either a vertex or an edge
selection. A vertex/edge can be added to a selection by holding the
control
key while clicking on it with the left mouse
button. Doing this again deselect the vertex/edge.
Selections can be made also from the Select
menu. The `Select
some vertices' dialog allows to give an expression for the vertices to
be selected: this can be a list of numeric R expessions separated by
commas, like `1,2:10,12,14,15
' for example. Similarly in the
`Select some edges' dialog two such lists can be given and all edges
connecting a vertex in the first list to one in the second list will
be selected.
In the color dialog a color name like 'orange' or RGB notation can also be used.
The tkplot
command creates a new Tk window with the graphical
representation of graph
. The command returns an integer number,
the tkplot id. The other commands utilize this id to be able to
query or manipulate the plot.
tkplot.close
closes the Tk plot with id tkp.id
.
tkplot.off
closes all Tk plots.
tkplot.fit.to.screen
fits the plot to the given rectange
(width
and height
), if some of these are NULL
the actual phisical width od height of the plot window is used.
tkplot.reshape
applies a new layout to the plot, its optional
parameters will be collected to a list analogous to layout.par
.
tkplot.export.postscript
creates a dialog window for saving the
plot in postscript format.
tkplot.getcoords
returns the coordinates of the vertices in a
matrix. Each row corresponds to one vertex.
tkplot.center
shifts the figure to the center of its plot window.
tkplot.rotate
rotates the figure, its parameter can be given
either in degrees or in radians.
tkplot
returns an integer, the id of the plot, this can be used
to manipulate it from the command line.
tkplot.getcoords
returns a matrix with the coordinates.
tkplot.close
, tkplot.off
, tkplot.fit.to.screen
,
tkplot.reshape
, tkplot.export.postscript
,
tkplot.center
and tkplot.rotate
return NULL
invisibly.
Gabor Csardi csardi@rmki.kfki.hu
g <- graph.ring(10) ## Not run: tkplot(g)