Skip to contents

scale_vertex_size() and scale_edge_width() linearly map a numeric data vector to a size range and record the mapping so that plot.igraph() draws a matching legend. Pass the result to vertex.size or edge.width, e.g. plot(g, vertex.size = scale_vertex_size(degree(g))).

Usage

scale_vertex_size(
  x,
  ...,
  range = c(2, 15),
  na_value = range[1],
  name = NULL,
  trans = NULL
)

scale_edge_width(
  x,
  ...,
  range = c(0.5, 6),
  na_value = range[1],
  name = NULL,
  trans = NULL
)

Arguments

x

A numeric data vector to map. Its length must be 1 or the number of vertices (edges) of the graph it is used with.

...

These dots are for future extensions and must be empty.

range

Numeric length-2 vector giving the output size range.

na_value

Size used for NA entries in x, and for entries that the transformation maps to a non-finite value (such as 0 under "log"). Defaults to the smallest size of range.

name

Optional guide title; defaults to the argument name.

trans

Optional transformation applied to x before rescaling, given as a function or its name (e.g. "sqrt", "log"). For "log", "log2", "log10" and "sqrt", the legend uses breaks that are evenly spaced on the transformed scale.

Value

An igraph_scale object.

Details

The keys of a vertex size legend are proportional to one another but are not drawn at the size of the plotted vertices, which depends on the device and the layout; they are kept within a legible range instead. The line samples of an edge width legend use the mapped widths directly.

See also

Other scales: scale_vertex_color()

Examples

g <- sample_pa(50, m = 2, directed = FALSE)
plot(g, vertex.size = scale_vertex_size(degree(g)), vertex.label = NA)

E(g)$weight <- runif(ecount(g))
plot(g, edge.width = scale_edge_width(E(g)$weight), vertex.label = NA)