[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] How to Add Colorbar to Graph
From: |
Matthew Walker |
Subject: |
Re: [igraph] How to Add Colorbar to Graph |
Date: |
Mon, 01 Feb 2010 11:16:32 -0500 |
User-agent: |
Thunderbird 2.0.0.23 (X11/20090812) |
Hi Lorenzo,
This might do your job. For fine-tuning see ?legend
layout(matrix(c(1,2), 1,2), widths=c(3,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)
plot.new()
colours = unique(colbar[V(g)$time])
labels = paste("label", 1:length(colours))
legend("center",legend=labels, col=colours, pch=19,
title="Title")
Cheers,
Matthew
Lorenzo Isella wrote:
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.
Cheers
Lorenzo
library(Cairo)
library(igraph)
set.seed(1234)
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)
CairoPDF("graph_with_colors.pdf")
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)
dev.off()
_______________________________________________
igraph-help mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/igraph-help