Skip to content
Prev 237 / 490 Next

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

Dear Steen,

There is no simple way to handle your problem. One possibility is to use the package 'network' which has a nicer algorithm to calculate the layout of nodes than pegas has. The good thing is that 'network' returns the coordinates which can then be input into plot.haploNet (see ?replot for something similar in pegas). Here's a possible solution:

## net3 is from your script
library(network)
xy <- plot(as.network(net3))
xy <- list(x = xy[, 1], y = xy[, 2])
size <- round(sqrt(attr(net3, "freq")))
plot(net3, size = size, xy = xy, pie = ind.hap3, legend = TRUE, threshold = 0)

Note the layout returned by network is random, so you can repeat the 2nd line above several times if you want, but it seems a single try is enough!

The second trick is to change the scale of the pie sizes using a square root transformation. I'm afraid that when the sizes of symbols are too contrasted, plot.haploNet() is really at a pain! I'll try to have a look at it if this can be improved.

In the last command, you'll still need to click on the plot to show where to draw the legend, but R will print the coordinates so these may be included in the script (or more simply you can delete the 'legend = TRUE' of you don't want the legend).

Note that you did a TCS network (has done by pegas::haploNet) which has a lot of alternative links (hence the 'threshold = 0' option). You may try an RMST network which has much less alternatives links:

d3 <- dist.dna(h3, "N", p = TRUE)
rmst3 <- rmst(d3)

Plotting can be done with:

xybis <- plot(as.network(rmst3))
xybis <- list(x = xybis[, 1], y = xybis[, 2])
plot(rmst3, size = sz, xy = xybis, pie = ind.hap3, legend = TRUE, threshold = 0)

Note that, if this is useful for you, you can use 'xy = xy' in the last command so that the layout of haplotypes will be identical with the two networks.

You may also look in more details this help page in network:

?network.layout.fruchtermanreingold

It explains how the change the parameters of the layout calculations.

HTH

Best,

Emmanuel

----- Le 2 Juin 22, ? 9:07, Steen Wilhelm Knudsen swknudsen at snm.ku.dk a ?crit :