net.bg <- barabasi.game(80) V(net.bg)$frame.color <- "white" V(net.bg)$color <- "orange" V(net.bg)$label <- "" V(net.bg)$size <- 10 E(net.bg)$arrow.mode <- 0 plot(net.bg)
plot(net.bg, layout=layout.random)
l <- layout.circle(net.bg) plot(net.bg, layout=l)
l
is the x- and y-coordinate matrix (N x 2) for N vertices of the graph. You can easily set them yourself: l <- matrix(c(1:vcount(net.bg), c(1, vcount(net.bg):2)), vcount(net.bg), 2) plot(net.bg, layout=l)
# l <- layout.random(net.bg) plot(net.bg, layout=l)
# l <- layout.circle(net.bg) plot(net.bg, layout=l)
# 3D- l <- layout.sphere(net.bg) plot(net.bg, layout=l)
area
(by default - the square of the number of vertices) and repulserad
(the radius of suppression for repulsion - area multiplied by the number of vertices). Both parameters affect the location of the chart - change them until you are satisfied with the result.l
allows you to get the same result many times, which can be useful if you need to build a graph change in time or different relationships - and you need to leave the vertices on the same places in several graphs.fruchterman.reingold.grid
similar to fruchterman.reingold
, but faster. l <- layout.fruchterman.reingold(net.bg, repulserad=vcount(net.bg)^3, area=vcount(net.bg)^2.4) par(mfrow=c(1,2), mar=c(0,0,0,0)) # - 1 , 2 plot(net.bg, layout=layout.fruchterman.reingold) plot(net.bg, layout=l)
dev.off() # , .
layout.spring()
called layout.spring()
. l <- layout.kamada.kawai(net.bg) plot(net.bg, layout=l) l <- layout.spring(net.bg, mass=.5) plot(net.bg, layout=l)
plot(net.bg, layout=layout.lgl)
rescale=FALSE
parameter and manually scale the graph by multiplying the coordinates by a number. The layout.norm
function allows layout.norm
to normalize the graph to the desired boundaries. l <- layout.fruchterman.reingold(net.bg) l <- layout.norm(l, ymin=-1, ymax=1, xmin=-1, xmax=1) par(mfrow=c(2,2), mar=c(0,0,0,0)) plot(net.bg, rescale=F, layout=l*0.4) plot(net.bg, rescale=F, layout=l*0.6) plot(net.bg, rescale=F, layout=l*0.8) plot(net.bg, rescale=F, layout=l*1.0)
dev.off()
layout.auto
. It automatically selects the required placement algorithm based on the properties of the graph (size and connectivity). layouts <- grep("^layout\\.", ls("package:igraph"), value=TRUE) # , . layouts <- layouts[!grepl("bipartite|merge|norm|sugiyama", layouts)] par(mfrow=c(3,3)) for (layout in layouts) { print(layout) l <- do.call(layout, list(net)) plot(net, edge.arrow.mode=0, layout=l, main=layout) } dev.off()
Source: https://habr.com/ru/post/266199/
All Articles