EVOLUTION-MANAGER
Edit File: plot.common.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Drawing graphs</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for Drawing graphs {igraph}"><tr><td>Drawing graphs {igraph}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Drawing graphs</h2> <h3>Description</h3> <p>The common bits of the three plotting functions <code>plot.igraph</code>, <code>tkplot</code> and <code>rglplot</code> are discussed in this manual page</p> <h3>Details</h3> <p>There are currently three different functions in the igraph package which can draw graph in various ways: </p> <p><code>plot.igraph</code> does simple non-interactive 2D plotting to R devices. Actually it is an implementation of the <code><a href="../../graphics/html/plot.html">plot</a></code> generic function, so you can write <code>plot(graph)</code> instead of <code>plot.igraph(graph)</code>. 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 <code><a href="plot.igraph.html">plot.igraph</a></code> for some more information. </p> <p><code><a href="tkplot.html">tkplot</a></code> does interactive 2D plotting using the <code>tcltk</code> package. It can only handle graphs of moderate size, a thousand vertices is probably already too many. Some parameters of the plotted graph can be changed interactively after issuing the <code>tkplot</code> command: the position, color and size of the vertices and the color and width of the edges. See <code><a href="tkplot.html">tkplot</a></code> for details. </p> <p><code><a href="rglplot.html">rglplot</a></code> is an experimental function to draw graphs in 3D using OpenGL. See <code><a href="rglplot.html">rglplot</a></code> for some more information. </p> <p>Please also check the examples below. </p> <h3>How to specify graphical parameters</h3> <p>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. </p> <p>The first method is to supply named arguments to the plotting commands: <code><a href="plot.igraph.html">plot.igraph</a></code>, <code><a href="tkplot.html">tkplot</a></code> or <code><a href="rglplot.html">rglplot</a></code>. Parameters for vertices start with prefix ‘<code>vertex.</code>’, parameters for edges have prefix ‘<code>edge.</code>’, and global parameters have no prefix. Eg. the color of the vertices can be given via argument <code>vertex.color</code>, whereas <code>edge.color</code> sets the color of the edges. <code>layout</code> gives the layout of the graphs. </p> <p>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 <code>color</code> vertex attribute and the color of the edges from the <code>color</code> edge attribute. The layout of the graph is given by the <code>layout</code> 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 ‘look’ to a graph, attributes are saved with the graph is you save it with <code><a href="../../base/html/save.html">save</a></code> or in GraphML format with <code><a href="write_graph.html">write_graph</a></code>, so the graph will have the same look after loading it again. </p> <p>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 <code><a href="igraph_options.html">igraph_options</a></code> are also checked. Vertex parameters have prefix ‘<code>vertex.</code>’, edge parameters are prefixed with ‘<code>edge.</code>’, general parameters like <code>layout</code> are prefixed with ‘<code>plot</code>’. These parameters are useful if you want all or most of your graphs to have the same look, vertex size, vertex color, etc. Then you don't need to set these at every plotting, and you also don't need to assign vertex/edge attributes to every graph. </p> <p>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. </p> <p>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 “proper” value of the parameter. (If the function returns another function object that will <em>not</em> be called again...) </p> <h3>The list of parameters</h3> <p>Vertex parameters first, note that the ‘<code>vertex.</code>’ prefix needs to be added if they are used as an argument or when setting via <code><a href="igraph_options.html">igraph_options</a></code>. 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.) </p> <dl> <dt>size</dt><dd><p>The size of the vertex, a numeric scalar or vector, in the latter case each vertex sizes may differ. This vertex sizes are scaled in order have about the same size of vertices for a given value for all three plotting commands. It does not need to be an integer number. </p> <p>The default value is 15. This is big enough to place short labels on vertices.</p> </dd> <dt>size2</dt><dd><p>The “other” size of the vertex, for some vertex shapes. For the various rectangle shapes this gives the height of the vertices, whereas <code>size</code> gives the width. It is ignored by shapes for which the size can be specified with a single number. </p> <p>The default is 15. </p> </dd> <dt>color</dt><dd><p>The fill color of the vertex. If it is numeric then the current palette is used, see <code><a href="../../grDevices/html/palette.html">palette</a></code>. If it is a character vector then it may either contain integer values, named colors or RGB specified colors with three or four bytes. All strings starting with ‘<code>#</code>’ are assumed to be RGB color specifications. It is possible to mix named color and RGB colors. Note that <code><a href="tkplot.html">tkplot</a></code> ignores the fourth byte (alpha channel) in the RGB color specification. </p> <p>For <code>plot.igraph</code> and integer values, the default igraph palette is used (see the ‘palette’ parameter below. Note that this is different from the R palette. </p> <p>If you don't want (some) vertices to have any color, supply <code>NA</code> as the color name. </p> <p>The default value is “<code>SkyBlue2</code>”. </p> </dd> <dt>frame.color</dt><dd><p>The color of the frame of the vertices, the same formats are allowed as for the fill color. </p> <p>If you don't want vertices to have a frame, supply <code>NA</code> as the color name. </p> <p>By default it is “black”. </p> </dd> <dt>frame.width</dt><dd><p>The width of the frame of the vertices. </p> <p>The default value is 1. </p> </dd> <dt>shape</dt><dd><p>The shape of the vertex, currently “<code>circle</code>”, “<code>square</code>”, “<code>csquare</code>”, “<code>rectangle</code>”, “<code>crectangle</code>”, “<code>vrectangle</code>”, “<code>pie</code>” (see <a href="vertex.shape.pie.html">vertex.shape.pie</a>), ‘<code>sphere</code>’, and “<code>none</code>” are supported, and only by the <code><a href="plot.igraph.html">plot.igraph</a></code> command. “<code>none</code>” does not draw the vertices at all, although vertex label are plotted (if given). See <code><a href="shapes.html">shapes</a></code> for details about vertex shapes and <code><a href="vertex.shape.pie.html">vertex.shape.pie</a></code> for using pie charts as vertices. </p> <p>The “<code>sphere</code>” vertex shape plots vertices as 3D ray-traced spheres, in the given color and size. This produces a raster image and it is only supported with some graphics devices. On some devices raster transparency is not supported and the spheres do not have a transparent background. See <code><a href="../../grDevices/html/dev.capabilities.html">dev.capabilities</a></code> and the ‘<code>rasterImage</code>’ capability to check that your device is supported. </p> <p>By default vertices are drawn as circles. </p> </dd> <dt>label</dt><dd><p>The vertex labels. They will be converted to character. Specify <code>NA</code> to omit vertex labels. </p> <p>The default vertex labels are the vertex ids. </p> </dd> <dt>label.family</dt><dd><p>The font family to be used for vertex labels. As different plotting commands can used different fonts, they interpret this parameter different ways. The basic notation is, however, understood by both <code><a href="plot.igraph.html">plot.igraph</a></code> and <code><a href="tkplot.html">tkplot</a></code>. <code><a href="rglplot.html">rglplot</a></code> does not support fonts at all right now, it ignores this parameter completely. </p> <p>For <code><a href="plot.igraph.html">plot.igraph</a></code> this parameter is simply passed to <code><a href="../../graphics/html/text.html">text</a></code> as argument <code>family</code>. </p> <p>For <code><a href="tkplot.html">tkplot</a></code> some conversion is performed. If this parameter is the name of an exixting Tk font, then that font is used and the <code>label.font</code> and <code>label.cex</code> 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 ‘symbol’ base family we used the symbol font is available, otherwise the first font which has ‘symbol’ in its name. If the parameter is not a name of the base families and it is also not a named Tk font then we pass it to <code><a href="../../tcltk/html/tkfont.create.html">tkfont.create</a></code> and hope the user knows what she is doing. The <code>label.font</code> and <code>label.cex</code> parameters are also passed to <code><a href="../../tcltk/html/tkfont.create.html">tkfont.create</a></code> in this case. </p> <p>The default value is ‘serif’. </p> </dd> <dt>label.font</dt><dd><p>The font within the font family to use for the vertex labels. It is interpreted the same way as the the <code>font</code> graphical parameter: 1 is plain text, 2 is bold face, 3 is italic, 4 is bold and italic and 5 specifies the symbol font. </p> <p>For <code><a href="plot.igraph.html">plot.igraph</a></code> this parameter is simply passed to <code><a href="../../graphics/html/text.html">text</a></code>. </p> <p>For <code><a href="tkplot.html">tkplot</a></code>, if the <code>label.family</code> 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. </p> <p>For <code><a href="rglplot.html">rglplot</a></code> it is ignored. </p> <p>The default value is 1. </p> </dd> <dt>label.cex</dt><dd><p>The font size for vertex labels. It is interpreted as a multiplication factor of some device-dependent base font size. </p> <p>For <code><a href="plot.igraph.html">plot.igraph</a></code> it is simply passed to <code><a href="../../graphics/html/text.html">text</a></code> as argument <code>cex</code>. </p> <p>For <code><a href="tkplot.html">tkplot</a></code> it is multiplied by 12 and then used as the <code>size</code> argument for <code><a href="../../tcltk/html/tkfont.create.html">tkfont.create</a></code>. The base font is thus 12 for tkplot. </p> <p>For <code><a href="rglplot.html">rglplot</a></code> it is ignored. </p> <p>The default value is 1. </p> </dd> <dt>label.dist</dt><dd> <p>The distance of the label from the center of the vertex. If it is 0 then the label is centered on the vertex. If it is 1 then the label is displayed beside the vertex. </p> <p>The default value is 0. </p> </dd> <dt>label.degree</dt><dd> <p>It defines the position of the vertex labels, relative to the center of the vertices. It is interpreted as an angle in radian, zero means ‘to the right’, and ‘<code>pi</code>’ means to the left, up is <code>-pi/2</code> and down is <code>pi/2</code>. </p> <p>The default value is <code>-pi/4</code>. </p> </dd> <dt>label.color</dt><dd><p>The color of the labels, see the <code>color</code> vertex parameter discussed earlier for the possible values. </p> <p>The default value is <code>black</code>. </p> </dd> </dl> <p>Edge parameters require to add the ‘<code>edge.</code>’ prefix when used as arguments or set by <code><a href="igraph_options.html">igraph_options</a></code>. The edge parameters: </p> <dl> <dt>color</dt><dd><p>The color of the edges, see the <code>color</code> vertex parameter for the possible values. </p> <p>By default this parameter is <code>darkgrey</code>. </p> </dd> <dt>width</dt><dd><p>The width of the edges. </p> <p>The default value is 1. </p> </dd> <dt>arrow.size</dt><dd><p>The size of the arrows. Currently this is a constant, so it is the same for every edge. If a vector is submitted then only the first element is used, ie. if this is taken from an edge attribute then only the attribute of the first edge is used for all arrows. This will likely change in the future. </p> <p>The default value is 1. </p> </dd> <dt>arrow.width</dt><dd><p>The width of the arrows. Currently this is a constant, so it is the same for every edge. If a vector is submitted then only the first element is used, ie. if this is taken from an edge attribute then only the attribute of the first edge is used for all arrows. This will likely change in the future. </p> <p>This argument is currently only used by <code><a href="plot.igraph.html">plot.igraph</a></code>. </p> <p>The default value is 1, which gives the same width as before this option appeared in igraph. </p> </dd> <dt>lty</dt><dd><p>The line type for the edges. Almost the same format is accepted as for the standard graphics <code><a href="../../graphics/html/par.html">par</a></code>, 0 and “blank” mean no edges, 1 and “solid” are for solid lines, the other possible values are: 2 (“dashed”), 3 (“dotted”), 4 (“dotdash”), 5 (“longdash”), 6 (“twodash”). </p> <p><code><a href="tkplot.html">tkplot</a></code> also accepts standard Tk line type strings, it does not however support “blank” lines, instead of type ‘0’ type ‘1’, ie. solid lines will be drawn. </p> <p>This argument is ignored for <code><a href="rglplot.html">rglplot</a></code>. </p> <p>The default value is type 1, a solid line. </p> </dd> <dt>label</dt><dd><p>The edge labels. They will be converted to character. Specify <code>NA</code> to omit edge labels. </p> <p>Edge labels are omitted by default.</p> </dd> <dt>label.family</dt><dd><p>Font family of the edge labels. See the vertex parameter with the same name for the details.</p> </dd> <dt>label.font</dt><dd><p>The font for the edge labels. See the corresponding vertex parameter discussed earlier for details.</p> </dd> <dt>label.cex</dt><dd><p>The font size for the edge labels, see the corresponding vertex parameter for details.</p> </dd> <dt>label.color</dt><dd><p>The color of the edge labels, see the <code>color</code> vertex parameters on how to specify colors. </p> </dd> <dt>label.x</dt><dd><p>The horizontal coordinates of the edge labels might be given here, explicitly. The <code>NA</code> elements will be replaced by automatically calculated coordinates. If <code>NULL</code>, then all edge horizontal coordinates are calculated automatically. This parameter is only supported by <code>plot.igraph</code>.</p> </dd> <dt>label.y</dt><dd><p>The same as <code>label.x</code>, but for vertical coordinates.</p> </dd> <dt>curved</dt><dd><p>Specifies whether to draw curved edges, or not. This can be a logical or a numeric vector or scalar. </p> <p>First the vector is replicated to have the same length as the number of edges in the graph. Then it is interpreted for each edge separately. A numeric value specifies the curvature of the edge; zero curvature means straight edges, negative values means the edge bends clockwise, positive values the opposite. <code>TRUE</code> means curvature 0.5, <code>FALSE</code> means curvature zero. </p> <p>By default the vector specifying the curvatire is calculated via a call to the <code><a href="curve_multiple.html">curve_multiple</a></code> function. This function makes sure that multiple edges are curved and are all visible. This parameter is ignored for loop edges. </p> <p>The default value is <code>FALSE</code>. </p> <p>This parameter is currently ignored by <code><a href="rglplot.html">rglplot</a></code>.</p> </dd> <dt>arrow.mode</dt><dd><p>This parameter can be used to specify for which edges should arrows be drawn. If this parameter is given by the user (in either of the three ways) then it specifies which edges will have forward, backward arrows, or both, or no arrows at all. As usual, this parameter can be a vector or a scalar value. It can be an integer or character type. If it is integer then 0 means no arrows, 1 means backward arrows, 2 is for forward arrows and 3 for both. If it is a character vector then “<” and “<-” specify backward, “>” and “->” forward arrows and “<>” and “<->” stands for both arrows. All other values mean no arrows, perhaps you should use “-” or “–” to specify no arrows. </p> <p>Hint: this parameter can be used as a ‘cheap’ solution for drawing “mixed” graphs: graphs in which some edges are directed some are not. If you want do this, then please create a <em>directed</em> graph, because as of version 0.4 the vertex pairs in the edge lists can be swapped in undirected graphs. </p> <p>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. </p> </dd> <dt>loop.angle</dt><dd><p>Gives the angle in radian for plotting loop edges. See the <code>label.dist</code> vertex parameter to see how this is interpreted. </p> <p>The default value is 0. </p> </dd> <dt>loop.angle2</dt><dd><p>Gives the second angle in radian for plotting loop edges. This is only used in 3D, <code>loop.angle</code> is enough in 2D. </p> <p>The default value is 0. </p> </dd> </dl> <p>Other parameters: </p> <dl> <dt>layout</dt><dd> <p>Either a function or a numeric matrix. It specifies how the vertices will be placed on the plot. </p> <p>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 <code>x</code> and <code>y</code> coordinates, and it can also have third column, this will be the <code>z</code> coordinate for 3D plots and it is ignored for 2D plots. </p> <p>If a two column matrix is given for the 3D plotting function <code><a href="rglplot.html">rglplot</a></code> then the third column is assumed to be 1 for each vertex. </p> <p>If <code>layout</code> is a function, this function will be called with the <code>graph</code> 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. </p> <p>The default value is <code>layout_nicely</code>, a smart function that chooses a layouter based on the graph.</p> </dd> <dt>margin</dt><dd><p>The amount of empty space below, over, at the left and right of the plot, it is a numeric vector of length four. Usually values between 0 and 0.5 are meaningful, but negative values are also possible, that will make the plot zoom in to a part of the graph. If it is shorter than four then it is recycled. </p> <p><code><a href="rglplot.html">rglplot</a></code> does not support this parameter, as it can zoom in and out the graph in a more flexible way. </p> <p>Its default value is 0. </p> </dd> <dt>palette</dt><dd><p>The color palette to use for vertex color. The default is <code><a href="categorical_pal.html">categorical_pal</a></code>, which is a color-blind friendly categorical palette. See its manual page for details and other palettes. This parameters is only supported by <code>plot</code>, and not by <code>tkplot</code> and <code>rglplot</code>. </p> </dd> <dt>rescale</dt><dd><p>Logical constant, whether to rescale the coordinates to the [-1,1]x[-1,1](x[-1,1]) interval. This parameter is not implemented for <code>tkplot</code>. </p> <p>Defaults to <code>TRUE</code>, the layout will be rescaled. </p> </dd> <dt>asp</dt><dd><p>A numeric constant, it gives the <code>asp</code> parameter for <code><a href="../../graphics/html/plot.html">plot</a></code>, the aspect ratio. Supply 0 here if you don't want to give an aspect ratio. It is ignored by <code>tkplot</code> and <code>rglplot</code>. </p> <p>Defaults to 1. </p> </dd> <dt>frame</dt><dd><p>Boolean, whether to plot a frame around the graph. It is ignored by <code>tkplot</code> and <code>rglplot</code>. </p> <p>Defaults to <code>FALSE</code>. </p> </dd> <dt>main</dt><dd><p>Overall title for the main plot. The default is empty if the <code>annotate.plot</code> igraph option is <code>FALSE</code>, and the graph's <code>name</code> attribute otherwise. See the same argument of the base <code>plot</code> function. Only supported by <code>plot</code>.</p> </dd> <dt>sub</dt><dd><p>Subtitle of the main plot, the default is empty. Only supported by <code>plot</code>.</p> </dd> <dt>xlab</dt><dd><p>Title for the x axis, the default is empty if the <code>annotate.plot</code> igraph option is <code>FALSE</code>, and the number of vertices and edges, if it is <code>TRUE</code>. Only supported by <code>plot</code>.</p> </dd> <dt>ylab</dt><dd><p>Title for the y axis, the default is empty. Only supported by <code>plot</code>.</p> </dd> </dl> <h3>Author(s)</h3> <p>Gabor Csardi <a href="mailto:csardi.gabor@gmail.com">csardi.gabor@gmail.com</a></p> <h3>See Also</h3> <p><code><a href="plot.igraph.html">plot.igraph</a></code>, <code><a href="tkplot.html">tkplot</a></code>, <code><a href="rglplot.html">rglplot</a></code>, <code><a href="igraph_options.html">igraph_options</a></code></p> <h3>Examples</h3> <pre> ## Not run: # 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") ## End(Not run) </pre> <hr /><div style="text-align: center;">[Package <em>igraph</em> version 1.3.5 <a href="00Index.html">Index</a>]</div> </body></html>