[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] how to subgraph layout coordinates
From: |
Gábor Csárdi |
Subject: |
Re: [igraph] how to subgraph layout coordinates |
Date: |
Sun, 1 Mar 2009 18:34:24 +0100 |
For example:
library(igraph)
g <- ba.game(20,m=2)
V(g)$name <- letters[1:vcount(g)]
l <- layout.norm(layout.kamada.kawai(g), -1, 1, -1, 1)
rownames(l) <- V(g)$name
plot(g, layout=l, vertex.color="#ff000022",
vertex.frame.color="#00000022", rescale=FALSE, vertex.label=NA)
my.vertices <- c(0,2:7)
g2 <- subgraph(g, my.vertices)
l2 <- l[ V(g)$name [ my.vertices+1 ], ]
plot(g2, layout=l2, add=TRUE, vertex.color="red", rescale=FALSE)
But actually it would be easier to add the layout as vertex
attribute(s), something like:
V(g)$x <- l[,1]
V(g)$y <- l[,2]
and then for the subgraph
plot(g2, layout=cbind(V(g)$x, V(g)$y), ....)
G.
On Sun, Mar 1, 2009 at 6:23 PM, Simone Gabbriellini
<address@hidden> wrote:
> thanks Gabor,
>
> can you please tell me also how to convert a list of label into a list
> of the correspondent vertex ids? Cause I have to subgraph and the ids
> switches so I need to find the same nodes using their labels...
>
>
> best regards,
> simone
>
> 2009/3/1 Gábor Csárdi <address@hidden>:
>> It is easier than that:
>>
>> l2 <- l[ my.vertices+1, ]
>>
>> The +1 is needed because igraph is 0-based, R is 1-based.
>>
>> Gabor
>>
>> On Sun, Mar 1, 2009 at 4:55 PM, Simone Gabbriellini
>> <address@hidden> wrote:
>>> List,
>>>
>>> I am trying to subset coordinates from a layout, because I want to
>>> plot over an existing plot, and I need the coordinates of nodes to be
>>> fixed
>>>
>>> I tryied something like:
>>>
>>> # list of my subset nodes
>>> core = c(1,2,3,4,5)
>>>
>>> l2 <- l[ which( V(g) == core ) ]
>>>
>>> but I got the error
>>>
>>> Warning message:
>>> In V(g) + 1 == core :
>>> longer object length is not a multiple of shorter object length
>>>
>>> can someone point me in the right direction?
>>>
>>> thanks,
>>> simone
>>>
>>>
>>> _______________________________________________
>>> igraph-help mailing list
>>> address@hidden
>>> http://lists.nongnu.org/mailman/listinfo/igraph-help
>>>
>>
>>
>>
>> --
>> Gabor Csardi <address@hidden> UNIL DGM
>>
>>
>> _______________________________________________
>> igraph-help mailing list
>> address@hidden
>> http://lists.nongnu.org/mailman/listinfo/igraph-help
>>
>
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>
--
Gabor Csardi <address@hidden> UNIL DGM