library(RGraphSpace)
library(igraph)
# Load a demo igraph
data('gtoy1', package = 'RGraphSpace')
# Create a new GraphSpace object
gs <- GraphSpace(gtoy1)
#--- Usage of GraphSpace attribute accessors:
# Vertex names
names(gs)
# Vertex attribute names
gs_names(gs)
# Get a data frame with nodes
gs_nodes(gs)
# Get a data frame with edges
gs_edges(gs)
# Get vertex count
gs_vcount(gs)
# Get edge count
gs_ecount(gs)
# Access all vertex attributes
gs_vertex_attr(gs)
# Access a specific vertex attribute
gs_vertex_attr(gs, "nodeLabel")
# Modify a single value within a vertex attribute
gs_vertex_attr(gs, "nodeSize")["n1"] <- 10
# Replace an entire vertex attribute
gs_vertex_attr(gs, "nodeSize") <- 10
# Access a specific edge attribute
gs_edge_attr(gs, "edgeColor")
# Replace an entire edge attribute
gs_edge_attr(gs, "edgeLineWidth") <- 1
# Add an image and rescale graph coordinates to image space
# Images may be provided as a raster or numeric matrix
gs_image(gs) <- as_colorraster(volcano)
gs <- normalizeGraphSpace(gs, image.space = FALSE)
# apply a scaling factor to node coordinates
gs_scale_factor(gs) <- 0.1
# undo scaling
gs_scale_factor(gs) <- 1
# add an 'sfc' geometry column
pts <- replicate(gs_vcount(gs), sf::st_point(runif(2)), simplify = FALSE)
gs_geometry(gs) <- sf::st_sfc(pts)
Run the code above in your browser using DataLab