[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] How to Add Colorbar to Graph

From: Lorenzo Isella
Subject: [igraph] How to Add Colorbar to Graph
Date: Mon, 01 Feb 2010 12:14:50 +0100
User-agent: Mozilla-Thunderbird (X11/20090707)

Dear All,
Please consider the code snippet at the end of the email.
It generates a network, highlights the diameter and paints each node according to a discrete variable I call "time". There are a few things I would like to add to the generated pdf (1) A colorbar, possible showing 8 discrete colors corresponding to the 8 possible values of my "time" variable
(2) I would like to be able to give a title to the colorbar
(3) I would like to be able to write some text corresponding to each color, to briefly explain what it stands for (I do not want to read simply 1,2...8 for each value in "time") (4) I also need the possibility of fine-tuning the size of the text I want to add to the plot, just to make sure it is readable in a figure for a publication.

Any help with (1)-(4) above is really appreciated.




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

n_col <- 8

my_seq <- rep(seq(n_col),10)

colbar <- rainbow(n_col)

V(g)$time <- my_seq

l <- layout.fruchterman.reingold(g)
l <- layout.norm(l, -1,1, -1,1)


plot(g, layout=l,
    vertex.label.dist=0.5,   vertex.color=colbar[V(g)$time],
vertex.frame.color="#ff000033", edge.color="#55555533",vertex.label=NA, vertex.size=4

d <- get.diameter(g,weights=NA)

V(g)$id <- seq(vcount(g))-1
g2 <- subgraph(g, d)
plot(g2, layout=l[ V(g2)$id+1, ],
vertex.color=colbar[V(g2)$time], vertex.frame.color="#ff000033",
  edge.color="#555555",vertex.label=NA, edge.width=2, vertex.size=4,
  add=TRUE, rescale=FALSE)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]