Skip to content
Prev 238 / 490 Next

How to avoid overlapping pies when plotting haplotype networks when using the packages 'pegas' and 'ape' in R

Another solution which works only with pegas: set the lengths of the links between haplotypes equal to the sum of the sizes of their respective symbols:

## extract the size of the haplotype symbols:
size <- attr(net3, "freq")
## make a copy of the network:
mynet <- net3
## change the lengths of the links by changing the 3th column:
mynet[, 3] <- size[net3[, 1]] + size[net3[, 2]]

We now plot the modified network:

o <- plot(mynet, size = size, cex = 0.8, pie = ind.hap3, threshold = 0, show.mutation = 0, scale.ratio = 2)

'o' is a list that includes (among other things) the coordinates; we extract them and adjust the names:

xy <- setNames(o[c("xx", "yy")], c("x", "y"))

We can plot the original network using these coordinates so that the mutations will be correctly displayed

plot(net3, xy = xy, size = size, cex = 0.8, pie = ind.hap3, threshold = 0, scale.ratio = 2, legend = TRUE)

The haplotype labels overlap quite a bit, so adding 'labels = FALSE' gives a nice result too (unless you want print these labels).

Best,

Emmanuel

----- Le 25 Juil 22, ? 18:45, Emmanuel Paradis emmanuel.paradis at ird.fr a ?crit :