如何在haploNet单倍型网络{pegas}中绘制饼图 [英] How to plot Pie charts in haploNet Haplotype Networks {pegas}

查看:423
本文介绍了如何在haploNet单倍型网络{pegas}中绘制饼图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用{pegas}的haploNet函数绘制单倍型网络,但是我很难将来自不同种群的相同单倍型放在同一饼图中.我可以使用以下脚本构建单倍型网络:

I'm trying to use haploNet function of {pegas} to plot a haplotype network, but i`m having trouble putting equal haplotypes from different populations in a same piechart. I can build a haplotype net with the following script:

x <- read.dna(file="x.fas",format="fasta")
h <- haplotype(x)
net <- haploNet(h)
plot(net)

我想在dnabin数据中设置每个分类单元的原始种群的标签,这样我可以在生成的网络中使用不同颜色(来自不同种群的单倍型)的饼图.我也想删除生成的单倍型网络中的重叠圆圈.

I'd like to set in the dnabin data the label of the original population of each taxa, so i could have piecharts of different colors (of haplotypes from different populations) in the resulting network. I'd like also to remove overlapping circles in the resulting haplotype network.

感谢您的帮助!

一个例子:

> data(woodmouse)
> x <- woodmouse[sample(15, size = 110, replace = TRUE), ]
> h <- haplotype(x)
> net <- haploNet(h)
> plot(net, size=attr(net, "freq"), scale.ratio = 2, cex = 0.8)

此脚本用于使用{pegas}构建单倍型网络.较大的圆圈代表更多的某种单倍型.我想知道如何在dnabin矩阵中设置单倍型的起源,以便它们在网络中以不同的颜色显示.

This script is used to build an haplotype network using {pegas}. The bigger circles represent much more haplotypes of some type. I`d like to know how I could set in the dnabin matrix the origin of the haplotypes, so they would appear with different colors in the network.

推荐答案

好,尝试从您的示例中弄清楚.看来您所拥有的种群是15个种群,每个种群有3-13个样本.

Ok, trying to make sense from your example. It appears the populations you have are 15 populations with anywhere from 3-13 samples per population.

table(rownames(x))

# No0906S No0908S No0909S No0910S No0912S No0913S No1007S 
#      10       8       6       3       3       7       6 
# No1103S No1114S No1202S No1206S No1208S   No304   No305 
#       4      13       9       6       9      13       7 
#   No306 
#       6

运行haplotype(x)时,(毫不奇怪)您将获得15个单倍型,这表示从人口到单倍型的1:1映射.我们可以使用

When you run haplotype(x), you get (unsurprisingly) 15 haplotypes representing a 1:1 mapping from population to haplotype. We can create a table showing the relationship between the populations and haplotypes with

ind.hap<-with(
    stack(setNames(attr(h, "index"), rownames(h))), 
    table(hap=ind, pop=rownames(x)[values])
)
ind.hap[1:10, 1:9]  #print just a chunk

#       pop
# hap    No0906S No0908S No0909S No0910S No0912S No0913S No1007S No1103S No1114S
#   I          0       0       0       0       0       0       0       0       0
#   II         0       0       0       0       0       0       6       0       0
#   III        0       0       0       0       0       0       0       4       0
#   IV        10       0       0       0       0       0       0       0       0
#   IX         0       0       0       0       0       0       0       0       0
#   V          0       0       6       0       0       0       0       0       0
#   VI         0       0       0       0       0       0       0       0       0
#   VII        0       0       0       0       0       7       0       0       0
#   VIII       0       0       0       0       0       0       0       0      13
#   X          0       0       0       0       0       0       0       0       0

我们可以在绘制过程中使用此表在每个节点上绘制图片字符.

We can use this table during plotting to draw pic chars at each of the nodes.

plot(net, size=attr(net, "freq"), scale.ratio = 2, cex = 0.8, pie=ind.hap)
legend(50,50, colnames(ind.hap), col=rainbow(ncol(ind.hap)), pch=20)

为了更好地展示饼图,我们可以为每个样本分配不正确的总体

To better show off the pie charts, we can assign incorrect populations to each of the samples

wrong.pop<-rep(letters[1:5], each=22)
ind.hap2<-with(
    stack(setNames(attr(h, "index"), rownames(h))), 
    table(hap=ind, pop=wrong.pop[values])
)

plot(net, size=attr(net, "freq"), scale.ratio = 2, cex = 0.8, pie=ind.hap2)
legend(50,50, colnames(ind.hap2), col=rainbow(ncol(ind.hap2)), pch=20)

在这里您可以看到每种单倍型都有更多的多样性,因为我们用人工名称错误地标记了种群,因此它们不会像簇一样好.

Here you can see we have more diversity at each haplotype because we've incorrectly labeled the populations with artificial names so they don't clump as nicely.

这篇关于如何在haploNet单倍型网络{pegas}中绘制饼图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆