plot.igraph
, tkplot
and rglplot
are discussed in
this manual page The first method is to supply named arguments to the plotting commands:
plot.igraph
, tkplot
or
rglplot
. Parameters for vertices start with prefix
vertex.
edge.
vertex.color
,
whereas edge.color
sets the color of the edges. layout
gives the layout of the graphs.
The second way is to assign vertex, edge and graph attributes to the
graph. These attributes have now prefix, ie. the color of the vertices
is taken from the color
vertex attribute and the color of the
edges from the color
edge attribute. The layout of the graph is
given by the layout
graph attribute. (Always assuming that the
corresponding command argument is not present.) Setting vertex and
edge attributes are handy if you want to assign a given save
or in GraphML format with
write.graph
, so the graph will have the same look after
loading it again.
If a parameter is not given in the command line, and the corresponding
vertex/edge/graph attribute is also missing then the general igraph
parameters handled by igraph.par
are also
checked. Vertex parameters have prefix vertex.
edge.
layout
are prefixed with plot
If the value of a parameter is not specified by any of the three ways described here, its default valued is used, as given in the source code.
Different parameters can have different type, eg. vertex colors can be
given as a character vector with color names, or as an integer vector
with the color numbers from the current palette. Different types are
valid for different parameters, this is discussed in detail in the
next section. It is however always true that the parameter can always
be a function object in which it will be called with the graph as its
single argument to get the
vertex.
igraph.par
. The value of the parameter may be scalar
valid for every vertex or a vector with a separate value for each
vertex. (Shorter vectors are recycled.)
The default value is 15. This is big enough to place short labels
on vertices.}
palette
. If it is a character vector then
it may either contain named colors or RGB specified colors with
three or four bytes. All strings starting with #}}
are assumed to be RGB color specifications. It is possible to mix
named color and RGB colors. Note that
tkplot
ignores
the fourth byte (alpha channel) in the RGB color specification.
The default value is SkyBlue2
By default it is NA
to omit vertex labels.
The default vertex labels are the vertex ids.
}
plot.igraph
and
tkplot
. rglplot
does not support fonts
at all right now, it ignores this parameter completely.
For plot.igraph
this parameter is simply passed to
text
as argument family
.
For tkplot
some
conversion is performed. If this parameter is the name of an
exixting Tk font, then that font is used and the label.font
and label.cex
parameters are ignored complerely. If it is
one of the base families (serif, sans, mono) then Times,
Helvetica or Courier fonts are used, there are guaranteed to exist
on all systems. For the tkfont.create
and hope the user knows what
she is doing. The label.font
and label.cex
parameters are also passed to tkfont.create
in this case.
The default value is font
graphical parameter: 1 is plain text, 2 is bold face,
3 is italic, 4 is bold and italic and 5 specifies the symbol
font.
For plot.igraph
this parameter is simply passed to
text
.
For tkplot
, if the label.family
parameter is
not the name of a Tk font then this parameter is used to set
whether the newly created font should be italic and/or
boldface. Otherwise it is ignored.
For rglplot
it is ignored.
The default value is 1.
}
For plot.igraph
it is simply passed to
text
as argument cex
.
For tkplot
it is multiplied by 12 and then used as
the size
argument for tkfont.create
.
The base font is thus 12 for tkplot.
For rglplot
it is ignored.
The default value is 1.
}
The default value is 0.
}
pi
-pi/2
and down is pi/2
.
The default value is -pi/4
.
}
color
vertex parameter discussed earlier for the possible values.
The default value is black
.
}
Edge parameters require to add the edge.
igraph.par
. The edge
parameters:
color
vertex
parameter for the possible values. By default this parameter is darkgrey
.
}
The default value is 1.
}
The default value is 1.
}
par
,
0 and
tkplot
also accepts standard Tk line type strings,
it does not however support rglplot
.
The default value is type 1, a solid line.
}
NA
to omit edge labels.
Edge labels are omitted by default.}
color
vertex parameters on how to specify colors. }
Hint: this parameter can be used as a
By default, no arrows will be drawn for undirected graphs, and for
directed graphs, an arrow will be drawn for each edge, according
to its direction. This is not very surprising, it is the expected
behavior.
}
label.dist
vertex parameter to see how this
is interpreted.
The default value is 0.
}
loop.angle
is enough
in 2D.
The default value is 0. } }
Other parameters:
x
and y
coordinates, and
it can also have third column, this will be the z
coordinate for 3D plots and it is ignored for 2D plots. If a two column matrix is given for the 3D plotting function
rglplot
then the third column is assumed to be 1 for
each vertex.
If layout
is a function, this function will be called with the
graph
as the single parameter to determine the
actual coordinates. The function should return a matrix with two
or three columns. For the 2D plots the third column is ignored.
The default value is layout.random
, ie. a function
returning with 2D random placement.}
rglplot
does not support this parameter, as it can
zoom in and out the graph in a more flexible way.
Its default value is 0.
}
plot.igraph
does simple non-interactive 2D plotting to R devices.
Actually it is an implementation of the plot
generic function,
so you can write plot(graph)
instead of
plot.igraph(graph)
. As it used the standard R devices it
supports every output format for which R has an output device. The
list is quite impressing: PostScript, PDF files, XFig files, SVG
files, JPG, PNG and of course you can plot to the screen as well using
the default devices, or the good-looking anti-aliased Cairo device.
See plot.igraph
for some more information.
tkplot
does interactive 2D plotting using the tcltk
package. It can only handle graphs of moderate size, a thousend
vertices is probably already too many. Some parameters of the plotted
graph can be changed interactively after issuing the tkplot
command: the position, color and size of the vertices and the color
and width of the edges. See tkplot
for details.
rglplot
is an experimental function to draw graphs in 3D
using OpenGL. See rglplot
for some more information.
Please also check the examples below.
plot.igraph
, tkplot
,
rglplot
, igraph.par
# plotting a simple ring graph, all default parameters, except the layout
g <- graph.ring(10)
g <- set.graph.attribute(g, "layout", layout.circle)
plot(g)
tkplot(g)
rglplot(g)
# plotting a random graph, set the parameters in the command arguments
g <- barabasi.game(100)
plot(g, layout=layout.fruchterman.reingold, vertex.size=4,
vertex.label.dist=0.5, vertex.color="red", edge.arrow.size=0.5)
# plot a random graph, different color for each component
g <- erdos.renyi.game(100, 1/100)
comps <- clusters(g)$membership
colbar <- rainbow(max(comps)+1)
V(g)$color <- colbar[comps+1]
plot(g, layout=layout.fruchterman.reingold, vertex.size=5, vertex.label=NA)
# plot communities in a graph
g <- graph.full(5)g <- add.edges(g, c(0,5, 0,10, 5,10))
com <- spinglass.community(g, spins=5)
V(g)$color <- com$membership+1
g <- set.graph.attribute(g, "layout", layout.kamada.kawai(g))
plot(g, vertex.label.dist=1.5)
# draw a bunch of trees, fix layout
igraph.par("plot.layout", layout.reingold.tilford)
plot(graph.tree(20, 2))
plot(graph.tree(50, 3), vertex.size=3, vertex.label=NA)
tkplot(graph.tree(50, 2), mode="undirected", vertex.size=10, vertex.color="green")
Run the code above in your browser using DataLab