library(RGraphSpace)
library(igraph)
library(ggplot2)
# Make a demo igraph
gtoy1 <- make_star(15, mode="out")
# Set some node attributes
V(gtoy1)$nodeSize <- runif(vcount(gtoy1), 1, 20)
V(gtoy1)$nodeColor <- rainbow(vcount(gtoy1))
# Set some variables
V(gtoy1)$user_var1 <- runif(vcount(gtoy1), 1, 3)^3
V(gtoy1)$user_var2 <- rep(c(1, 2, 3), each = 5)
# Create a GraphSpace object
gs <- GraphSpace(gtoy1, layout = layout_in_circle(gtoy1))
if (FALSE) {
# Example 1: Nodes scaling with the legend
# When 'size' is mapped inside aes(), it follows
# ggplot2 default behavior: size is translated
# to absolute units (mm) via 'scale_size()'.
ggplot(gs) +
geom_edgespace(arrow_offset = 0.01) +
geom_nodespace(mapping = aes(size = nodeSize, fill = user_var2)) +
scale_size(range = c(1, 12)) +
theme(aspect.ratio = 1)
# Example 2: Nodes scaling with the viewport
# When 'size' is passed as a node attribute,
# inherited from the igraph object, it is
# interpreted as a percentage of the plotting
# area and translated to NPC units.
ggplot(gs) +
geom_edgespace(arrow_offset = 0.01) +
geom_nodespace(mapping = aes(fill = user_var2)) +
theme(aspect.ratio = 1)
# Example 3: Node labels
ggplot(gs) +
geom_edgespace() +
geom_nodespace(aes(label = nodeLabel)) +
theme(aspect.ratio = 1)
}
Run the code above in your browser using DataLab