Skip to contents

scale_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 to categorical_pal(). For numeric x, the anchor colours of the ramp; defaults to sequential_pal().

na_value

Colour used for NA entries in x (and, for numeric x, infinite ones).

name

Optional guide title; defaults to the name of the argument the scale is assigned to (e.g. "vertex.color").

Value

An igraph_scale object.

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()

Examples

g <- make_graph("Zachary")
V(g)$faction <- ifelse(seq_len(vcount(g)) <= 17, "A", "B")
plot(g, vertex.color = scale_vertex_color(V(g)$faction))

plot(g, vertex.color = scale_vertex_color(degree(g), name = "Degree"))