igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] How to optimise layout without 'area' option?


From: Tamas Nepusz
Subject: Re: [igraph] How to optimise layout without 'area' option?
Date: Wed, 9 Mar 2016 11:44:29 +0100

Hello,

Ah, okay - I might have misunderstood your original question (for some
reason I was thinking that the original problem was that the connected
components diverged in the layout from each other, resulting in an
unusable layout).

I'm afraid that there is no way to control the distance between the
individual connected components in a layout generated by igraph right
now. I would probably tackle the problem by post-processing the layout
a bit:

1) Identify the center of mass for each of the connected components in
the layout
2) Scale the vertices of each connected component around the center of
mass of the component with a scaling factor. (Factors larger than 1
will make the components get closer to each other, while factors
smaller than 1 will increase the distance between the components).

I know that this is a bit cumbersome, but I cannot think of any easier
solution right now.

T.


On Mon, Mar 7, 2016 at 6:04 PM, Mostowy, Rafal J
<address@hidden> wrote:
> Thanks. I understand the basic concept (though yes, the example you sent is 
> helpful. however I still don’t understand how to control the spread between 
> the connected components. Previously, the area function affected the area 
> across which they’re spread but now I don’t see the appropriate variable. Is 
> there an analogous parameter in the layout_components() function?
>
>
>> On 7 Mar 2016, at 12:31, Tamas Nepusz <address@hidden> wrote:
>>
>> Hi,
>>
>> You don't need any function for merging the layouts;
>> layout_components() will do this for you:
>>
>>> library(igraph)
>>> g <- make_ring(5) * 4
>>> layout <- layout_components(g, layout=layout_with_fr)
>>> plot(g, layout=layout)
>>
>> Basically, layout_components will decompose the graph into its
>> connected components, then call the given layout function
>> (layout_with_fr in the above example) for all the components, merges
>> the layouts, and returns a single unified layout that is suitable for
>> the original graph. Any additional arguments supplied to
>> layout_components() are forwarded to the actual component-wise layout
>> function.
>>
>> All the best,
>> T.
>>
>>
>> On Mon, Mar 7, 2016 at 1:20 PM, Mostowy, Rafal J
>> <address@hidden> wrote:
>>> Hi Tamas,
>>>
>>> Thanks a lot for your reply. This sounds like a y complicated solution of 
>>> the problem. I'm saying this because before I would just vary one parameter 
>>> and get the result I wanted, whereas now I'd need to design an entire 
>>> function to merge the connected components. Is there a simple way of doing 
>>> that? Would you be willing to give a simple exaple? The one on the help 
>>> page doesn't seem to do what I need.
>>>
>>> Thanks a lot,
>>> R
>>>
>>>> On 5 Mar 2016, at 20:48, Tamas Nepusz <address@hidden> wrote:
>>>>
>>>> Hi,
>>>>
>>>> The new implementation of the Fruchterman-Reingold layout does not
>>>> have the "area" option any more, but you can try using
>>>> layout_components() - this will decompose the graph into connected
>>>> components first, lay out the connected components separately, and
>>>> then merge the layouts.
>>>>
>>>> T.
>>>>
>>>>
>>>> On Sat, Mar 5, 2016 at 2:56 PM, Mostowy, Rafal J
>>>> <address@hidden> wrote:
>>>>> I'm trying to optimise the layout of a network I'm constructing with the 
>>>>> following code:
>>>>>
>>>>> gr <- read.table("data.txt", header = F, stringsAsFactors = F)
>>>>> node.names <- gr[,1]
>>>>> node.names <- toupper(substr(node.names, 2, nchar(node.names)))
>>>>> gr <- gr[,-1]
>>>>> edge.table.index <- which(gr>0.5, arr.ind=T)
>>>>> d <- data.frame(first = node.names[edge.table.index[,1]], second = 
>>>>> node.names[edge.table.index[,2]])
>>>>> g <- graph.data.frame(d, directed=F)
>>>>> g[from=V(g), to=V(g)] <- 0
>>>>> layout.g <- layout.fruchterman.reingold(g)
>>>>> plot(g, layout = layout.g, vertex.size = 5, vertex.label.cex=.7, 
>>>>> vertex.color = "lightblue", vertex.label.family = "sans", 
>>>>> edge.color="black", vertex.frame.color= "white")
>>>>>
>>>>> In particular, what I'm trying to do is decrease the area on which the 
>>>>> nodes are displayed such that the connected components are closer 
>>>>> together. Previous versions of igraph had the option 'area' in the 
>>>>> layout.fruchterman.reingold() function but this doesn't seem to be the 
>>>>> case anymore. I've tried playing with various options like vertex size, 
>>>>> vertex font size and width/height of the exported pdf file but they don't 
>>>>> really do the trick.
>>>>>
>>>>> Does anyone have a suggestion? I’m attaching a link to the data.
>>>>>
>>>>> Thanks,
>>>>> Rafal
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> ________________
>>>>> Rafal Mostowy, PhD
>>>>> Junior Research Fellow
>>>>> Department of Infectious Disease Epidemiology
>>>>> Imperial College London
>>>>> St Mary's Campus
>>>>> Norfolk Place
>>>>> London W2 1PG
>>>>> email: address@hidden
>>>>> twitter: @RafalMostowy
>>>>> website: http://rmostowy.wordpress.com
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> igraph-help mailing list
>>>>> address@hidden
>>>>> https://lists.nongnu.org/mailman/listinfo/igraph-help
>>>>
>>>> _______________________________________________
>>>> igraph-help mailing list
>>>> address@hidden
>>>> https://lists.nongnu.org/mailman/listinfo/igraph-help
>>>
>>> _______________________________________________
>>> igraph-help mailing list
>>> address@hidden
>>> https://lists.nongnu.org/mailman/listinfo/igraph-help
>>
>> _______________________________________________
>> igraph-help mailing list
>> address@hidden
>> https://lists.nongnu.org/mailman/listinfo/igraph-help
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/igraph-help



reply via email to

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