How-to: Construct petridish plots in R

September 14, 2012
By

(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:

A sample petridish plot generated in R using the igraph package

 

 

 

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...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)