# Shortly, I generate a network of genetic variants, that have
# defined ancestor-descendant-relationships progressing over time in a
# coalescent process and spreading over space (directed edges). That process
# is reconstructed by so-called haplotype-trees or networks. The sampled
# haplotypes per location were then allocated with certain probabilities to an
# optimal number of genetic clusters that show genetic similarity of
# haplotypes. These cluster probabilities give the proportions for the vertex
# pies to demonstrate the mixture of genetic variants in sampling sites over
# space. The network, however can also contain virtually reconstructed
# haplotypes that were not actually been sampled but inferred by the
# coalescent as potential intermediate evolutionary steps. Thus these nodes
# have no geolocation nor a cluster allocation at all by definition. The
# problem is that these nodes are also labelled but have proportion NA in each
# cluster which is not allowed for the pie argument. I liked to set these
# virtual nodes to transparency with labels, but did not manage to perform
# that task. I get the error message "
# Fehler in seq.int(values[i], values[i + 1], length.out = n) :
# 'length.out' muss eine nicht-negative Zahl sein
# ", and in the plot the labels disappear. Any help is highly appreciated.
# Below you find my basic plotting code.
#sessionInfo()
#R version 2.15.3 (2013-03-01)
#Platform: i386-w64-mingw32/i386 (32-bit)
#locale:
# [1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252
#[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
#[5] LC_TIME=German_Germany.1252
#attached base packages:
# [1] grDevices datasets splines graphics stats tcltk utils
#[8] methods base
#other attached packages:
# [1] jpeg_0.1-2 png_0.1-4 XML_3.95-0.2 igraph_0.6.5-1
#[5] svSocket_0.9-54 svIDE_0.9-50 TinnR_1.0-5 R2HTML_2.2
#[9] Hmisc_3.10-1 survival_2.37-4
#loaded via a namespace (and not attached):
# [1] cluster_1.14.3 grid_2.15.3 lattice_0.20-13 svMisc_0.9-68
#[5] tools_2.15.3
#>
# load needed library "igraph"
library("igraph")
# my graph is a haplotype network
GraphEdgesSub <-
structure(list(178, TRUE, c(166, 166, 164, 167, 136, 136, 165,
94, 130, 163, 163, 75, 75, 155, 159, 129, 129, 151, 128, 128,
128, 134, 18, 65, 65, 126, 138, 115, 115, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 46, 49, 137, 83, 22, 107, 108, 112, 64,
48, 48, 80, 80, 45, 135, 67, 119, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 68, 1, 1, 5, 5, 5, 12,
13, 26, 98, 106, 106, 110, 110, 111, 148, 58, 58, 58, 58, 10,
104, 40, 105, 109, 120, 120, 121, 156, 57, 70, 168, 27, 27, 131,
160, 170, 20, 122, 152, 172, 139, 141, 141, 174, 145, 147, 176,
142, 144, 175, 61, 61, 61, 61, 61, 61, 61, 61, 61, 173, 87, 90,
90, 96, 96, 96, 96, 113, 113, 116, 149, 150, 171, 117, 118, 140,
54, 177, 157, 158, 169, 146, 35, 35, 35, 125, 161, 162, 143,
114, 123, 55, 153, 154, 132, 124, 133), c(164, 167, 136, 165,
94, 130, 163, 93, 75, 155, 159, 95, 129, 100, 151, 128, 134,
18, 65, 126, 138, 115, 16, 46, 47, 49, 137, 59, 83, 17, 21, 22,
29, 34, 39, 52, 72, 107, 108, 112, 64, 50, 48, 80, 45, 19, 23,
102, 135, 66, 67, 81, 119, 0, 127, 68, 82, 1, 2, 3, 5, 11, 12,
13, 24, 26, 28, 33, 37, 38, 42, 53, 73, 98, 106, 110, 111, 148,
63, 58, 10, 104, 6, 7, 8, 40, 105, 109, 99, 15, 120, 41, 121,
51, 156, 56, 57, 70, 168, 9, 4, 27, 14, 25, 31, 131, 44, 160,
71, 69, 170, 20, 30, 122, 152, 172, 139, 32, 141, 174, 145, 43,
147, 176, 142, 144, 175, 61, 88, 173, 78, 79, 87, 90, 96, 113,
116, 149, 150, 171, 117, 92, 118, 86, 97, 103, 140, 54, 177,
77, 157, 158, 169, 85, 91, 146, 35, 125, 161, 162, 89, 143, 60,
114, 123, 55, 153, 154, 101, 74, 132, 124, 76, 84, 36, 133, 62
), c(57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
71, 72, 73, 74, 75, 76, 77, 80, 81, 82, 83, 84, 99, 85, 86, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 22, 116, 44, 87, 111,
112, 162, 163, 164, 101, 53, 40, 49, 50, 41, 156, 171, 108, 95,
96, 97, 98, 130, 131, 132, 133, 134, 135, 136, 137, 138, 48,
23, 24, 55, 79, 109, 11, 12, 51, 52, 43, 140, 141, 142, 7, 143,
144, 145, 146, 88, 100, 102, 89, 90, 45, 46, 103, 91, 92, 93,
47, 147, 148, 169, 27, 28, 149, 153, 154, 56, 104, 105, 106,
117, 170, 175, 165, 25, 78, 18, 19, 20, 15, 16, 8, 113, 174,
176, 21, 54, 4, 5, 42, 26, 120, 155, 121, 122, 127, 168, 128,
124, 161, 125, 94, 150, 151, 17, 118, 172, 173, 13, 107, 158,
159, 14, 114, 166, 167, 9, 10, 2, 6, 0, 1, 3, 110, 160, 115,
152, 119, 139, 123, 129, 126, 157), c(53, 57, 58, 59, 100, 60,
82, 83, 84, 99, 80, 61, 62, 63, 102, 89, 22, 29, 17, 45, 111,
30, 31, 46, 64, 103, 65, 101, 66, 32, 112, 104, 117, 67, 33,
156, 174, 68, 69, 34, 85, 91, 70, 121, 106, 44, 23, 24, 42, 25,
41, 93, 35, 71, 147, 165, 95, 96, 79, 27, 162, 127, 176, 78,
40, 18, 49, 50, 55, 109, 97, 108, 36, 72, 169, 8, 172, 149, 130,
131, 43, 51, 56, 28, 173, 153, 143, 132, 128, 160, 133, 154,
141, 7, 4, 11, 134, 144, 73, 88, 13, 168, 47, 145, 81, 86, 74,
37, 38, 87, 75, 76, 39, 135, 163, 21, 136, 140, 142, 52, 90,
92, 113, 164, 171, 157, 19, 54, 15, 12, 5, 105, 170, 175, 16,
48, 2, 26, 20, 116, 146, 118, 124, 161, 125, 120, 155, 122, 77,
137, 138, 14, 114, 166, 167, 9, 94, 150, 151, 10, 107, 158, 159,
6, 0, 3, 1, 98, 152, 110, 139, 115, 129, 119, 126, 123, 148),
c(0, 21, 23, 23, 23, 23, 26, 26, 26, 26, 26, 27, 27, 28,
29, 29, 29, 40, 40, 41, 41, 42, 42, 43, 43, 43, 43, 44, 46,
46, 46, 46, 46, 46, 46, 46, 49, 49, 49, 49, 49, 50, 50, 50,
50, 50, 51, 52, 52, 54, 55, 55, 55, 55, 55, 56, 57, 57, 58,
62, 62, 62, 71, 71, 71, 72, 74, 74, 75, 76, 76, 77, 77, 77,
77, 77, 79, 79, 79, 79, 79, 81, 81, 81, 82, 82, 82, 82, 83,
83, 83, 85, 85, 85, 85, 86, 86, 90, 90, 91, 91, 91, 91, 91,
91, 92, 93, 95, 96, 97, 98, 100, 101, 102, 104, 105, 107,
108, 109, 110, 111, 113, 114, 115, 116, 117, 118, 119, 120,
123, 125, 126, 127, 128, 129, 130, 131, 133, 134, 135, 136,
137, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 162,
163, 164, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
176, 177), 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, 54, 55, 56, 57, 58,
59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102,
103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138,
139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150,
151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162,
163, 164, 165, 166, 166, 167, 168, 169, 170, 171, 172, 173,
174, 175, 176, 177), list(c(1, 0, 1), structure(list(), .Names = character(0)),
structure(list(name = c("1", "3", "5", "13", "16", "21",
"24", "25", "36", "38", "41", "43", "47", "49", "52",
"57", "58", "61", "62", "66", "68", "69", "70", "75",
"77", "78", "79", "81", "83", "85", "88", "92", "93",
"98", "100", "102", "103", "109", "111", "114", "118",
"120", "121", "124", "125", "127", "128", "129", "130",
"131", "132", "145", "147", "150", "153", "154", "155",
"156", "157", "162", "167", "169", "171", "173", "174",
"175", "176", "178", "182", "186", "188", "189", "193",
"194", "196", "200", "202", "205", "207", "208", "209",
"211", "212", "213", "215", "216", "217", "218", "219",
"221", "222", "224", "225", "226", "227", "229", "230",
"231", "236", "237", "240", "241", "243", "245", "246",
"247", "248", "249", "250", "251", "252", "253", "254",
"255", "256", "257", "258", "259", "260", "261", "262",
"263", "264", "265", "266", "267", "268", "269", "270",
"271", "272", "274", "275", "276", "277", "278", "279",
"280", "281", "282", "283", "284", "285", "286", "287",
"288", "289", "290", "291", "292", "293", "294", "295",
"296", "297", "298", "299", "300", "301", "302", "303",
"304", "305", "306", "307", "308", "309", "310", "311",
"312", "313", "314", "315", "316", "317", "318", "319",
"320")), .Names = "name"), list())), class = "igraph")
#my proportion list for vertex.shape = "pie"
# The list- object "row.mat" contains the cluster proportions (summing up to
# 1000) for 5 genetic clusters for 179 haplotypes in total. The haplotype
# numbers 1 to 104 have been found in mixed proportions in locations, the
# haplotypes 105 to 179 are reconstructed and have proportions "NA".
row.mat <-
list(c(643, 73, 0, 4, 280), c(270, 178, 0, 11, 541), c(268, 178,
0, 11, 544), c(268, 178, 0, 11, 544), c(283, 178, 0, 11, 528),
c(268, 178, 0, 11, 544), c(268, 178, 0, 11, 544), c(268,
178, 0, 11, 544), c(268, 178, 0, 11, 544), c(270, 178, 0,
11, 541), c(270, 178, 0, 11, 541), c(268, 178, 0, 11, 544
), c(896, 3, 0, 0, 100), c(891, 3, 0, 1, 106), c(891, 3,
0, 1, 106), c(786, 52, 0, 4, 159), c(912, 17, 0, 2, 70),
c(912, 17, 0, 2, 70), c(804, 99, 0, 7, 90), c(912, 17, 0,
2, 70), c(927, 3, 0, 0, 70), c(912, 17, 0, 2, 70), c(886,
17, 0, 2, 95), c(912, 17, 0, 2, 70), c(892, 3, 0, 0, 106),
c(889, 6, 0, 0, 106), c(889, 6, 0, 0, 106), c(898, 3, 0,
0, 99), c(892, 3, 0, 0, 106), c(912, 17, 0, 2, 70), c(898,
3, 0, 0, 99), c(786, 52, 0, 4, 159), c(786, 52, 0, 4, 159
), c(881, 7, 0, 0, 112), c(912, 17, 0, 2, 70), c(686, 310,
0, 0, 5), c(686, 310, 0, 0, 5), c(885, 4, 0, 1, 111), c(892,
3, 0, 0, 106), c(912, 17, 0, 2, 70), c(897, 3, 0, 0, 100),
c(715, 55, 0, 4, 227), c(886, 6, 0, 2, 106), c(749, 63, 0,
3, 185), c(715, 55, 0, 4, 227), c(880, 17, 0, 2, 101), c(0,
46, 887, 59, 8), c(0, 46, 887, 59, 8), c(0, 32, 951, 10,
6), c(0, 46, 887, 59, 8), c(0, 46, 887, 59, 8), c(622, 77,
0, 6, 294), c(911, 17, 0, 2, 70), c(879, 8, 0, 2, 111), c(686,
310, 0, 0, 5), c(697, 303, 0, 0, 0), c(0, 28, 960, 6, 6),
c(0, 28, 960, 6, 6), c(0, 28, 960, 6, 6), c(0, 209, 691,
91, 8), c(686, 310, 0, 0, 5), c(233, 374, 18, 374, 0), c(697,
303, 0, 0, 0), c(0, 46, 887, 59, 8), c(0, 46, 887, 59, 8),
c(0, 46, 887, 59, 8), c(0, 28, 959, 7, 6), c(0, 38, 944,
10, 8), c(0, 38, 944, 10, 8), c(0, 28, 960, 6, 6), c(0, 28,
960, 6, 6), c(0, 28, 960, 6, 6), c(911, 17, 0, 2, 70), c(268,
178, 0, 11, 544), c(686, 271, 0, 1, 42), c(0, 248, 670, 72,
10), c(243, 348, 25, 384, 1), c(245, 364, 22, 369, 1), c(62,
395, 26, 517, 1), c(63, 395, 25, 516, 1), c(0, 300, 390,
306, 3), c(0, 300, 390, 306, 3), c(0, 300, 390, 306, 3),
c(0, 300, 390, 306, 3), c(304, 349, 17, 330, 0), c(62, 387,
26, 525, 1), c(68, 386, 26, 519, 1), c(62, 387, 26, 525,
1), c(749, 63, 0, 3, 185), c(0, 28, 960, 6, 6), c(62, 388,
26, 525, 1), c(62, 387, 26, 525, 1), c(62, 388, 26, 525,
1), c(16, 338, 538, 78, 31), c(16, 338, 540, 77, 30), c(0,
249, 652, 89, 10), c(68, 386, 26, 519, 1), c(68, 386, 26,
519, 1), c(268, 178, 0, 11, 544), c(266, 178, 0, 11, 545),
c(404, 135, 365, 63, 33), c(17, 346, 37, 599, 1), c(912,
17, 0, 2, 70), c(68, 386, 26, 519, 1), c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_))
#vertex.pie.color
colorcode <- c(7, 5, 6, 3, 2, 8)
# plot.igraph
set.seed(12345)
plot.igraph(GraphEdgesSub, layout=layout.kamada.kawai,
vertex.shape="pie", vertex.pie=row.mat,
vertex.pie.color=list(colorcode),
vertex.size=5, vertex.label=V(GraphEdgesSub)$name,
vertex.label.cex=0.6, vertex.label.font=2,
edge.color="black", edge.arrow.size = 0.1)
# error message
#Fehler in seq.int(values[i], values[i + 1], length.out = n) :
#'length.out' muss eine nicht-negative Zahl sein