igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Node Overlap and Positioning


From: Lorenzo Isella
Subject: Re: [igraph] Node Overlap and Positioning
Date: Fri, 1 Dec 2017 09:20:30 +0100

Thanks everybody for their help!
I will try out your suggestions and post again if I have trouble.
Just for the record, being an avid ggplot2 user, I am also considering ggraph for making panel plots of networks, but this is another story.
Cheers

Lorenzo

On 1 December 2017 at 00:11, George Vega Yon <address@hidden> wrote:
Lorenzo,

I suggest you take a look at the rgexf package (which I maintain), in particular, the development version https://github.com/gvegayon/rgexf which has a bunch of new features including an integration with the gexf-js _javascript_ library which allows you to get Gephi-like viz on the browser. That said, here is an example of a couple of things that I would do with the data that you are sharing:

1. Create a new plotting device, and on top of that add the igraph plot. That gives you more control and allows you to, say, not restrict yourself to the square layout.

2. Use either white or some other color for the frame

3. Tryout netdiffuseR::igraph_vertex_rescale function. This function from the netdiffuseR R package, which I maintain as well, allows rescaling vertex size so that instead of using absolute values you can define how much of the plotting device, in percentage, will the largest and smallest node occupy.

Below an example including the plot

HIH

library(igraph)

g <- structure(list(28, FALSE, c(6, 6, 8, 9, 10, 10, 11, 12, 13, 14, 
                                 15, 16, 16, 17, 17, 17, 17, 17, 17, 18, 18, 19, 19, 19, 20, 20, 
                                 20, 20, 20, 20, 21, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24, 
                                 25, 25, 25, 25, 25, 25, 26, 26, 26, 27, 27, 27), c(1, 2, 2, 3, 
                                                                                    2, 7, 6, 1, 4, 10, 2, 1, 12, 1, 3, 5, 6, 10, 13, 7, 15, 14, 17, 
                                                                                    18, 0, 1, 2, 14, 18, 19, 0, 6, 7, 0, 9, 18, 17, 20, 22, 5, 7, 
                                                                                    11, 0, 8, 10, 18, 22, 24, 6, 9, 14, 4, 21, 25), c(0, 1, 2, 3, 
                                                                                                                                      4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
                                                                                                                                      21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 
                                                                                                                                      37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 
                                                                                                                                      53), c(24, 30, 33, 42, 0, 7, 11, 13, 25, 1, 2, 4, 10, 26, 3, 
                                                                                                                                             14, 8, 51, 15, 39, 6, 16, 31, 48, 5, 19, 32, 40, 43, 34, 49, 
                                                                                                                                             9, 17, 44, 41, 12, 18, 21, 27, 50, 20, 22, 36, 23, 28, 35, 45, 
                                                                                                                                             29, 37, 52, 38, 46, 47, 53), c(0, 0, 0, 0, 0, 0, 0, 2, 2, 3, 
                                                                                                                                                                            4, 6, 7, 8, 9, 10, 11, 13, 19, 21, 24, 30, 33, 36, 39, 42, 48, 
                                                                                                                                                                            51, 54), c(0, 4, 9, 14, 16, 18, 20, 24, 28, 29, 31, 34, 35, 36, 
                                                                                                                                                                                       37, 40, 41, 41, 43, 47, 48, 49, 50, 52, 52, 53, 54, 54, 54), 
                    list(c(1, 0, 1), structure(list(name = "Erdos renyi (gnp) graph", 
                                                    type = "gnp", loops = FALSE, p = 0.142857142857143), .Names = c("name", 
                                                                                                                    "type", "loops", "p")), structure(list(names = c("BE", "BG", 
                                                                                                                                                                     "CZ", "DK", "DE", "EE", "IE", "EL", "ES", "FR", "IT", "CY", 
                                                                                                                                                                     "LV", "LT", "LU", "HU", "MT", "NL", "AT", "PL", "PT", "RO", 
                                                                                                                                                                     "SI", "SK", "FI", "SE", "UK", "HR")), .Names = "names"), 
                         structure(list(weight = c(16.3104184714332, 30.7293642773093, 
                                                   1.51651715633125, 46.5498389394643, 117.400128622748, 
                                                   9116.96298628885, 1101.62292417749, 12.3449820775232, 
                                                   158.642126867059, 1.81516408646891, 760.982895191571, 
                                                   1011.05564809154, 31677.1638228568, 189.344972592696, 
                                                   13.1424122833109, 66.5517926330624, 12.0922729908787, 
                                                   4.58139821481045, 90.1042955878783, 3.71064650396136, 
                                                   90.4281997569113, 158.365362288124, 46.6972207187443, 
                                                   30.3317841283049, 7.78960961626955, 1.95560245248322, 
                                                   697.72330148994, 58.3866681241721, 660.780592399842, 
                                                   1.30621866244087, 90.6566452600129, 411.372413931909, 
                                                   50.4594917412583, 30.747955195432, 5.22931377396076, 
                                                   26225.4597289607, 518.792688616195, 12998.9635603034, 
                                                   69.4202716300456, 8.21344218621299, 0.582827301648975, 
                                                   8.09867531337074, 107.652085596974, 1142.61073604216, 
                                                   116.541846414264, 1.62280326041373, 405.914678311703, 
                                                   0.386623934247936, 18.218603738158, 21.1501080346551, 
                                                   0.158066706508139, 862.791072359265, 8.42653129127126, 
                                                   20.0432021225717)), .Names = "weight"))),  class = "igraph")

g <- upgrade_graph(g)

## l <- layout.fruchterman.reingold(g)

l <- layout_with_dh(g)

l <- layout.norm(l, -1,1, -1,1) 


l <- norm_coords(layout.graphopt(g), xmin=-2, xmax=2, ymin=-2, ymax=2)


set.seed(1234)
# pdf("toy-network.pdf")

# I rather puttin the plot on a new plotting device
oldpar <- par(no.readonly = TRUE)
par(
  mar = rep(2,4),
  xpd = NA # This ensures you don't clip the images
  )

plot.new()
plot.window(
  xlim = range(l[,1]),
  ylim = range(l[,2])
  )

plot(g,  layout=l,
     ## rescale=F, ylim=c(0.4,2.6), xlim=c(-3.4, -1.7),
     ## vertex.label.dist=0.5,
     vertex.color=adjustcolor("blue", .5),
     
     # White works nicer for the borders
     # vertex.frame.color="#ff000033",
     vertex.frame.color= "white",
     
     edge.color="#55555533",
     vertex.label=V(g)$names,
     vertex.label.color="black",
     
     # You can use netdiffuseR
     # vertex.size=log(strength(g))*2,
     vertex.size = netdiffuseR::igraph_vertex_rescale(
       vertex.size = strength(g),
       minmax.relative.size = c(.025, .1)
       
       ),
     
     
     edge.width=  log(1+E(g)$weight)
     , edge.curved=0.3,
     edge.label=NA,
     # NEW OPTIONS
     add = TRUE,
     rescale=FALSE
     )


par(oldpar)
# dev.off()



On Thu, Nov 30, 2017 at 5:52 AM, Esteban Moro <address@hidden> wrote:
Hi Lorenzo.

As far as I can see, the layout in the visualization corresponds to the geographical coordinates for each country. So that’s why nodes have no overlap and bigger nodes (France, Italy, GBR, DEU) appear in the center

Best


Esteban Moro Egido
Visiting Professor, MIT Media Lab
Associate Professor, Universidad Carlos III de Madrid
estebanmoro.org



El 30 nov 2017, a las 7:54, Lorenzo Isella <address@hidden> escribió:

Dear All,
I have not used the igraph in a long time, so I am a bit rusty.
Essentially, I would like to make a nice eye-catching plot of a simple network.
Please have a look at

https://ged-project.de/research/studies/factory-europe/

where if you scroll down a bit you find a nice visualization.
I like it because

1) there is no overlapping between the nodes
2) the bigger nodes have a rather central position in the network plot
3) the edges are curved in a very smooth way.


As to 1), from my googling, it appears that igraph has no concept of node size, so you have to fine tune the layout, xlim,ylim and node size yourself. Or has anything changed at this regard?

For 2), what is the recommended layout?

For 3), yes, I can bend the edges, but the result is not nearly as smooth as in that network visualization.
To fix the ideas, please have a look at the self contained example at the end of the email.
Any suggestion is appreciated.
Cheers

Lorenzo


##########################################################

library(igraph)

g <- structure(list(28, FALSE, c(6, 6, 8, 9, 10, 10, 11, 12, 13, 14,
15, 16, 16, 17, 17, 17, 17, 17, 17, 18, 18, 19, 19, 19, 20, 20,
20, 20, 20, 20, 21, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24,
25, 25, 25, 25, 25, 25, 26, 26, 26, 27, 27, 27), c(1, 2, 2, 3,
2, 7, 6, 1, 4, 10, 2, 1, 12, 1, 3, 5, 6, 10, 13, 7, 15, 14, 17,
18, 0, 1, 2, 14, 18, 19, 0, 6, 7, 0, 9, 18, 17, 20, 22, 5, 7,
11, 0, 8, 10, 18, 22, 24, 6, 9, 14, 4, 21, 25), c(0, 1, 2, 3,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
53), c(24, 30, 33, 42, 0, 7, 11, 13, 25, 1, 2, 4, 10, 26, 3,
14, 8, 51, 15, 39, 6, 16, 31, 48, 5, 19, 32, 40, 43, 34, 49,
9, 17, 44, 41, 12, 18, 21, 27, 50, 20, 22, 36, 23, 28, 35, 45,
29, 37, 52, 38, 46, 47, 53), c(0, 0, 0, 0, 0, 0, 0, 2, 2, 3,
4, 6, 7, 8, 9, 10, 11, 13, 19, 21, 24, 30, 33, 36, 39, 42, 48,
51, 54), c(0, 4, 9, 14, 16, 18, 20, 24, 28, 29, 31, 34, 35, 36,
37, 40, 41, 41, 43, 47, 48, 49, 50, 52, 52, 53, 54, 54, 54),
    list(c(1, 0, 1), structure(list(name = "Erdos renyi (gnp) graph",
        type = "gnp", loops = FALSE, p = 0.142857142857143), .Names = c("name",
    "type", "loops", "p")), structure(list(names = c("BE", "BG",
    "CZ", "DK", "DE", "EE", "IE", "EL", "ES", "FR", "IT", "CY",
    "LV", "LT", "LU", "HU", "MT", "NL", "AT", "PL", "PT", "RO",
    "SI", "SK", "FI", "SE", "UK", "HR")), .Names = "names"),
        structure(list(weight = c(16.3104184714332, 30.7293642773093,
        1.51651715633125, 46.5498389394643, 117.400128622748,
        9116.96298628885, 1101.62292417749, 12.3449820775232,
        158.642126867059, 1.81516408646891, 760.982895191571,
        1011.05564809154, 31677.1638228568, 189.344972592696,
        13.1424122833109, 66.5517926330624, 12.0922729908787,
        4.58139821481045, 90.1042955878783, 3.71064650396136,
        90.4281997569113, 158.365362288124, 46.6972207187443,
        30.3317841283049, 7.78960961626955, 1.95560245248322,
        697.72330148994, 58.3866681241721, 660.780592399842,
        1.30621866244087, 90.6566452600129, 411.372413931909,
        50.4594917412583, 30.747955195432, 5.22931377396076,
        26225.4597289607, 518.792688616195, 12998.9635603034,
        69.4202716300456, 8.21344218621299, 0.582827301648975,
        8.09867531337074, 107.652085596974, 1142.61073604216,
        116.541846414264, 1.62280326041373, 405.914678311703,
        0.386623934247936, 18.218603738158, 21.1501080346551,
        0.158066706508139, 862.791072359265, 8.42653129127126,
        20.0432021225717)), .Names = "weight"))),  class = "igraph")

g <- upgrade_graph(g)

## l <- layout.fruchterman.reingold(g)

l <- layout_with_dh(g)

l <- layout.norm(l, -1,1, -1,1)


l <- norm_coords(layout.graphopt(g), xmin=-2, xmax=2, ymin=-2, ymax=2)


set.seed(1234)
pdf("toy-network.pdf")

plot(g,  layout=l,
     ## rescale=F, ylim=c(0.4,2.6), xlim=c(-3.4, -1.7),
     ## vertex.label.dist=0.5,
     vertex.color=adjustcolor("blue", .5),
     vertex.frame.color="#ff000033",
     edge.color="#55555533",
     vertex.label=V(g)$names,
     vertex.label.color="black",
     vertex.size=log(strength(g))*2,
     edge.width=  log(1+E(g)$weight)
    , edge.curved=0.3,
     edge.label=NA    )


dev.off()

_______________________________________________
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]