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)).
Arguments
- by
A numeric vector of scores to rank by, e.g.
degree(g)orbetweenness(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
nbyby), a non-negative whole number. Entries tied with then-th are kept too, so more thannlabels may remain. Give eithernorprop, 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
norprop, not both.- labels
The labels to thin. Defaults to
names(by)if present, otherwise the integer positions. Must have the same length asby.- decreasing
Logical; if
TRUE(the default) the highestbyvalues are kept, otherwise the lowest.
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))
