[R] network
Dry, Jonathan R
Jonathan.Dry at astrazeneca.com
Fri Jul 11 16:32:15 CEST 2008
Thnaks
Ignore the forst problem - seems to solve itself!
Trying 'V(g)$label <- V(g)$name' I recieve the following error:
Error in `V<-`(`*tmp*`, value = 0:9) : invalid indexing
The full code used (with matrix shown) is below - any help appreciated:
> data2
G1 G2 G3 G4 G5 G6 G7 G8 G9 G10
G1 0 0 0 0 0 0.000 0.000 0.000 0 0
G2 0 0 0 0 0 -0.356 0.000 0.000 0 0
G3 0 0 0 0 0 0.000 0.319 0.000 0 0
G4 0 0 0 0 0 0.000 0.000 0.429 0 0
G5 0 0 0 0 0 0.000 0.000 -0.419 0 0
G6 0 0 0 0 0 0.000 0.000 0.000 0 0
G7 0 0 0 0 0 0.000 0.000 0.000 0 0
G8 0 0 0 0 0 0.000 0.000 0.000 0 0
G9 0 0 0 0 0 0.000 0.000 0.000 0 0
G10 0 0 0 0 0 0.000 0.000 0.000 0 0
> gdata2 <- graph.adjacency(data2, weighted=TRUE, mode="upper")
> E(gdata2)$color <- "green"
> E(gdata2)[ weight<0 ]$color <- "red"
> gdata2$layout <- layout.fruchterman.reingold
> V(gdata2)$label <- V(data2)$name
Error in V(data2) : Not a graph object
> V(gdata2)$label <- V(gdata2)$name
Error in `V<-`(`*tmp*`, value = 0:9) : invalid indexing
> gdata2
Vertices: 10
Edges: 4
Directed: FALSE
Edges:
[0] 1 -- 5
[1] 2 -- 6
[2] 3 -- 7
[3] 4 -- 7
>
-----Original Message-----
From: Gabor Csardi [mailto:csardi at rmki.kfki.hu]
Sent: 11 July 2008 14:54
To: Dry, Jonathan R
Cc: R Help list
Subject: Re: [R] network
Jonathan,
please stay on the list.
The first query i don't understand, can you send a pdf or explain
a bit what exactly happens.
As for the names, use them as row or column names in the matrix
(see ?colnames), and then do
V(g)$label <- V(g)$name
before the plotting.
G.
On Fri, Jul 11, 2008 at 02:47:55PM +0100, Dry, Jonathan R wrote:
> Superb - thanks Gabor
>
> Two minor queries - firstly the network plot does not seem to fit in the window and so only part of it is plotted. Secondly, the first row and column of my matrix comprise the sample names - is it possible to show the names in the nodes of the graph (currently it just shows the row number)?
>
> Your help is much appreciated
>
> Kind regards
>
> Jonathan
>
> -----Original Message-----
> From: Gabor Csardi [mailto:csardi at rmki.kfki.hu]
> Sent: 11 July 2008 14:33
> To: Dry, Jonathan R
> Cc: r-help at r-project.org
> Subject: Re: [R] network
>
>
> I'm sure this is possible with 'network', but i'm not very familiar
> with that package. In case you don't get an answer on how
> to do it with network, here is how to do it with the 'igraph' package:
>
> library(igraph)
> M <- matrix(runif(100)*2-1, 10, 10)
> M[ lower.tri(M, diag=TRUE) ] <- 0
>
> M[ abs(M) < 0.5] <- 0
>
> g <- graph.adjacency(M, weighted=TRUE, mode="upper")
> E(g)$color <- "green"
> E(g)[ weight<0 ]$color <- "red"
>
> g$layout <- layout.fruchterman.reingold
> plot(g)
>
> Please tell me if something is not clear,
> Gabor
>
> On Fri, Jul 11, 2008 at 02:04:54PM +0100, Dry, Jonathan R wrote:
> > Hello
> >
> > I am a relatively new user of R and am struggling to use the 'network' package. I have a correlation matrix (produced using 'cor'), and want to draw a network where each item showing correlation above a threshold (say 0.5) is joined by a green line, and each item showing correlation below a threshold (say -0.5) is joined by a red line. Does anyone have any hints of how to correctly use functions within the 'network' package to achieve this?
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> --
> Csardi Gabor <csardi at rmki.kfki.hu> UNIL DGM
--
Csardi Gabor <csardi at rmki.kfki.hu> UNIL DGM
More information about the R-help
mailing list