The common bits of the three plotting functions
rglplot are discussed in
this manual page
There are currently three different functions in the igraph package which can draw graph in various ways:
plot.igraph does simple non-interactive 2D plotting to R devices.
Actually it is an implementation of the
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.
plot.igraph for some more information.
tkplot does interactive 2D plotting using the
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
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.
How to specify graphical parameters
There are three ways to give values to the parameters described below, in section 'Parameters'. We give these three ways here in the order of their precedence.
The first method is to supply named arguments to the plotting commands:
rglplot. Parameters for vertices start with prefix
edge.color sets the color of the edges.
gives the layout of the graphs.
The second way is to assign vertex, edge and graph attributes to the
graph. These attributes have no 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_options are also
checked. Vertex parameters have prefix
layout are prefixed with
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
# plotting a simple ring graph, all default parameters, except the layout g <- make_ring(10) g$layout <- layout_in_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_with_fr, 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 <- sample_gnp(100, 1/100) comps <- components(g)$membership colbar <- rainbow(max(comps)+1) V(g)$color <- colbar[comps+1] plot(g, layout=layout_with_fr, vertex.size=5, vertex.label=NA) # plot communities in a graph g <- make_full_graph(5) %du% make_full_graph(5) %du% make_full_graph(5) g <- add_edges(g, c(1,6, 1,11, 6,11)) com <- cluster_spinglass(g, spins=5) V(g)$color <- com$membership+1 g <- set_graph_attr(g, "layout", layout_with_kk(g)) plot(g, vertex.label.dist=1.5) # draw a bunch of trees, fix layout igraph_options(plot.layout=layout_as_tree) plot(make_tree(20, 2)) plot(make_tree(50, 3), vertex.size=3, vertex.label=NA) tkplot(make_tree(50, 2, mode="undirected"), vertex.size=10, vertex.color="green")