Skip to contents

label_top() returns a label vector with NA everywhere except the entries that rank highest by by. Because plot.igraph() omits NA labels, this is a convenient way to declutter dense graphs by labelling only the most important vertices (or edges). Pass it to a label argument, e.g. plot(g, vertex.label = label_top(degree(g), n = 10)).

Usage

label_top(by, ..., n = NULL, prop = NULL, labels = NULL, decreasing = TRUE)

Arguments

by

A numeric vector of scores to rank by, e.g. degree(g) or betweenness(g). One score per vertex (or edge). Entries with a missing score are never kept.

...

These dots are for future extensions and must be empty.

n

Number of labels to keep (the top n by by), a non-negative whole number. Entries tied with the n-th are kept too, so more than n labels may remain. Give either n or prop, not both. If neither is given, all labels with a score are kept.

prop

Proportion of labels to keep, between 0 and 1; rounded up. Give either n or prop, not both.

labels

The labels to thin. Defaults to names(by) if present, otherwise the integer positions. Must have the same length as by.

decreasing

Logical; if TRUE (the default) the highest by values are kept, otherwise the lowest.

Value

A character vector the same length as by, with NA in the positions that are not kept.

Details

To label everything above a fixed cutoff instead of a fixed count, you do not need this helper: ifelse(metric > cutoff, labels, NA) works directly.

Examples

g <- make_graph("Zachary")
plot(g, vertex.label = label_top(degree(g), n = 3))