
Map data to vertex or edge colours with an automatic legend
Source:R/plot-scales.R
scale_vertex_color.Rdscale_vertex_color() and scale_edge_color() map a data vector to
colours and record the mapping so that plot.igraph() draws a matching
guide. Pass the result to a colour argument of the matching kind, e.g.
plot(g, vertex.color = scale_vertex_color(V(g)$group)) or
plot(g, edge.color = scale_edge_color(E(g)$type)).
Usage
scale_vertex_color(x, ..., palette = NULL, na_value = "grey70", name = NULL)
scale_edge_color(x, ..., palette = NULL, na_value = "grey70", name = NULL)Arguments
- x
The 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.
- palette
Colours to map to. For discrete
x, a vector of colours (one per level, recycled); defaults tocategorical_pal(). For numericx, the anchor colours of the ramp; defaults tosequential_pal().- na_value
Colour used for
NAentries inx(and, for numericx, infinite ones).- name
Optional guide title; defaults to the name of the argument the scale is assigned to (e.g.
"vertex.color").
Details
A non-numeric x (factor, character, logical) produces a discrete mapping
and a categorical legend; a numeric x produces a continuous mapping (a
colour ramp) and a colorbar.
See also
Other scales:
scale_vertex_size()

