Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

node_angle

Get the angle of nodes and edges


Description

These helper functions makes it easy to calculate the angle associated with nodes and edges. For nodes the angle is defined as the angle of the vector pointing towards the node position, and is thus mainly suited for circular layouts where it can be used to calculate the angle of labels. For edges it is simply the angle of the vector describing the edge.

Usage

node_angle(x, y, degrees = TRUE)

edge_angle(x, y, xend, yend, degrees = TRUE)

Arguments

x, y

A vector of positions

degrees

Logical. Should the angle be returned in degree (TRUE) or radians (FALSE). Defaults to TRUE.

xend, yend

The end position of the edge

Value

A vector with the angle of each node/edge

Examples

require(tidygraph)
flareGraph <- tbl_graph(flare$vertices, flare$edges)

ggraph(flareGraph, 'dendrogram', circular = TRUE) +
  geom_edge_diagonal0() +
  geom_node_text(aes(filter = leaf, angle = node_angle(x, y), label = shortName),
    hjust = 'outward', size = 2
  ) +
  expand_limits(x = c(-1.3, 1.3), y = c(-1.3, 1.3))

ggraph

An Implementation of Grammar of Graphics for Graphs and Networks

v2.0.5
MIT + file LICENSE
Authors
Thomas Lin Pedersen [cre, aut] (<https://orcid.org/0000-0002-5147-4711>), RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.