[R] igraph tree: increase vertex separation within tier (self-contained example)
Loris Bennett
loris.bennett at fu-berlin.de
Mon Sep 14 17:05:25 CEST 2015
Loris Bennett <loris.bennett at fu-berlin.de> writes:
> Hi,
>
> I am collecting data about network errors and would like to visualise
> the results in some sort of graph which reflects the hierarchy of the
> components in the network (i.e. core switches are connected to leaf
> switches and nodes are connected to leaf switches).
>
> The errors are in file which looks something like this:
>
> --------
> 2015-07-15;coreswitch01;1;0
> 2015-07-15;coreswitch01;2;0
> 2015-07-15;leafswitch01;1;0
> 2015-07-15;leafswitch01;2;0
> 2015-07-15;leafswitch01;3;0
> 2015-07-15;leafswitch01;4;0
> 2015-07-15;leafswitch01;5;0
> 2015-07-15;leafswitch02;1;0
> 2015-07-15;leafswitch02;2;0
> 2015-07-15;leafswitch02;3;0
> 2015-07-15;leafswitch02;4;0
> 2015-07-15;leafswitch02;5;0
> 2015-07-15;leafswitch02;2;561
> 2015-07-15;node001;1;0
> 2015-07-15;node002;1;0
> 2015-07-15;node003;1;0
> 2015-07-15;node004;1;3
> 2015-07-15;node005;1;10529
> 2015-07-15;node007;1;0
> 2015-07-15;node008;1;2081
> --------
>
> and the topology file, which relates ports to ports and ports to
> multiport components, looks something like this:
>
> --------
> coreswitch01;coreswitch01_01
> coreswitch01;coreswitch01_02
> leafswitch01;leafswitch01_01
> leafswitch01;leafswitch01_02
> leafswitch01;leafswitch01_03
> leafswitch01;leafswitch01_04
> leafswitch01;leafswitch01_05
> leafswitch02;leafswitch02_01
> leafswitch02;leafswitch02_02
> leafswitch02;leafswitch02_03
> leafswitch02;leafswitch02_04
> leafswitch02;leafswitch02_05
> coreswitch01_01;leafswitch01_01
> coreswitch01_02;leafswitch02_01
> leafswitch01_02;node001_01
> leafswitch01_03;node002_01
> leafswitch01_04;node003_01
> leafswitch01_05;node004_01
> leafswitch02_02;node005_01
> leafswitch02_03;node006_01
> leafswitch02_04;node007_01
> leafswitch02_05;node008_01
> --------
>
>
> I'm plotting the data with the following:
>
> --------
> library("igraph")
>
> error_data <- read.csv(file="errors.csv",head=FALSE,sep=";")
> colnames(error_data) <- c("datetime","name","portnumber","generic_error");
>
> topo_data <- read.csv(file="topology.csv",head=FALSE,sep=";")
> G <-graph.data.frame(topo_data, directed=F)
>
> error_counter <- 'generic_error'
> error_counter_max <- max(error_data[,error_counter])
>
> vcolours <- 100 - round(99*error_data[,error_counter]/error_counter_max)
> hc100 <- heat.colors(100)
> vcolour_values <- hc100[vcolours]
>
> l <- layout_(G,as_tree(root=c(1),rootlevel=c(1)))
>
> plot(G, layout = l, vertex.shape = "rectangle", vertex.color=vcolour_values)
> --------
>
> This produces roughly what I want. However, even with this subset of
> the full network, there is quite a lot of overlapping of vertex labels
> within the lowest tier. The full data set has over 100 vertices on the
> lowest tier, which causes the labels to become illegible. I can adjust
> the aspect ratio of the plot and/or the canvas, but this doesn't affect
> the separation between the vertices.
>
> Does anyone have any advice about how to display such information?
> (Completely different approaches also welcome.)
>
> Cheers,
>
> Loris
Here's a self-contained version of the above:
========
library("igraph")
error_data <- structure(list(datetime = structure(c(1L, 1L, 1L, 1L, 1L, 1L,1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "2015-07-15", class = "factor"),name = structure(c(1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L,3L, 3L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L), .Label = c("coreswitch01","leafswitch01", "leafswitch02", "node001", "node002", "node003","node004", "node005", "node007", "node008"), class = "factor"),portnumber = c(1L, 2L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L,5L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), generic_error = c(0L,0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 561L, 0L, 0L,0L, 3L, 10529L, 0L, 2081L)), .Names = c("datetime", "name","portnumber", "generic_error"), class = "data.frame", row.names = c(NA,-20L))
colnames(error_data) <- c("datetime","name","portnumber","generic_error");
#topo_data <- read.csv(file="topology.csv",head=FALSE,sep=";")
topo_data <- structure(list(V1 = structure(c(1L, 1L, 4L, 4L, 4L, 4L, 4L, 9L, 9L, 9L, 9L, 9L, 2L, 3L, 5L, 6L, 7L, 8L, 10L, 11L, 12L, 13L), .Label = c("coreswitch01", "coreswitch01_01", "coreswitch01_02", "leafswitch01", "leafswitch01_02", "leafswitch01_03", "leafswitch01_04", "leafswitch01_05", "leafswitch02", "leafswitch02_02", "leafswitch02_03", "leafswitch02_04", "leafswitch02_05"), class = "factor"), V2 = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 3L, 8L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L), .Label = c("coreswitch01_01", "coreswitch01_02", "leafswitch01_01", "leafswitch01_02", "leafswitch01_03", "leafswitch01_04", "leafswitch01_05", "leafswitch02_01", "leafswitch02_02", "leafswitch02_03", "leafswitch02_04", "leafswitch02_05", "node001_01", "node002_01", "node003_01", "node004_01", "node005_01", "node006_01", "node007_01", "node008_01"), class = "factor")), .Names = c("V1", "V2"), class = "data.frame", row.names = c(NA, -22L))
G <-graph.data.frame(topo_data, directed=F)
error_counter <- 'generic_error'
error_counter_max <- max(error_data[,error_counter])
vcolours <- 100 - round(99*error_data[,error_counter]/error_counter_max)
hc100 <- heat.colors(100)
vcolour_values <- hc100[vcolours]
l <- layout_(G,as_tree(root=c(1),rootlevel=c(1)))
plot(G, layout = l, vertex.shape = "rectangle", vertex.color=vcolour_values)
========
The question is how the aspect ratio can be changed to prevent the node
labels overlapping. An ideal solution would accommodate around 100
nodes on the lowest tier of the diagram.
Cheers,
Loris
--
This signature is currently under construction.
More information about the R-help
mailing list