Bonono
Bonono

Reputation: 847

Testing graph planarity in R

Is there a way of testing whether a network graph is planar in R? I've looked in igraph but to no avail.

I know I can with MATLAB using BGL toolbox but I want to know if anyone has tried it in R.

Upvotes: 5

Views: 1089

Answers (1)

emilliman5
emilliman5

Reputation: 5966

The RBGL package within bioconductor has what you are looking for. RBGL provides an interface to the Boost library for graph analysis (C++)

source("https://bioconductor.org/biocLite.R")
biocLite("RBGL")

library(RBGL)
library(igraph)

set.seed(1234)
g <- erdos.renyi.game(20, 1/5) ##Make an igraph graph
plot(g)

g <- as_graphnel(g) ## Convert igraph object to graphNEL object for planarity testing
boyerMyrvoldPlanarityTest(g)

# [1] FALSE

g <- erdos.renyi.game(20, 1/8)
plot(g)

g <- as_graphnel(g)
boyerMyrvoldPlanarityTest(g)
# [1] TRUE

Non Planar graph

Non-planar

Planar graph

PLanar

Upvotes: 6

Related Questions