(This article was first published on

**Pirate Science » R**, and kindly contributed to R-bloggers)** Script for petridish layout in R**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
library(igraph) # create empty graph g <- graph.empty(directed=FALSE) node_id <- c(1:1000) # add nodes g <- add.vertices(g, nv=1000, vert_colour=sample(c('blue','red','yellow','green','purple'),1000,replace=T)) # add edges E <- sample(0:999,2000,replace=T) g <- add.edges(g,E) # optimize layout lay <- layout.fruchterman.reingold(g) # plot graph plot(g,layout=lay,vertex.label='',vertex.size=2,vertex.color=V(g)$vert_colour) |

**Plot generated for this example**:

To

**leave a comment**for the author, please follow the link and comment on their blog:**Pirate Science » R**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...