# How-to: Construct petridish plots in R

[This article was first published on

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

**Pirate Science » R**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

** 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 about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.