我正在尝试在R中创建单倍型网络。我已经能够毫无问题地绘制它,但是尽管使用了scale.ratio值,但是在重叠节点方面存在一些问题。所以我想使用tkplot并手动进行我需要的更改,但是我没有运气介绍我在常规绘图函数下使用的饼图和大小值。
我对R很新,所以我希望我不知道自己在做什么,而不是尝试一些不可行的东西:)
提前感谢您的帮助!
这是我到目前为止的代码:
library(pegas)
library(plyr)
library(reshape)
library(igraph)
# Load the alignment
alignment<-read.dna("ON-A-SNP-data - Copy2.fas", format="fasta")
# Load the sites
sites<-read.csv("SITES.csv")
# Calculate haplotype frequencies
h<-haplotype(alignment)
# Build the haplotype network based on the haplotype frequencies.
net<-haploNet(h)
# Add column for haplotypes
sites<-cbind(sites,haplotype=rep(NA, nrow(sites)))
# Assign haplotypes to the samples automatically using a loop
for (i in 1:length(labels(h))){
sites$haplotype[attr(h, "index")[[i]]]<-i
}
# Build a matrix of frequencies that will tell R how to fill pies on haplotype network. #Requires the packages 'plyr' and 'reshape'.
dfcount<-ddply(sites,.(site,haplotype),summarise,freq=length(site))
dc <- cast(haplotype ~ site, data = dfcount, value = "freq", fill = 0)
dc$haplotype<-NULL
dc<-as.matrix(as.data.frame(dc))
# Plot the haplotype network
plot(net, size=attr(net, "freq"), scale.ratio = 3, pie = dc, fast=TRUE, labels=FALSE)
如果这有用,这是'net'的输出?
> net
step Prob
[1,] 10 9 1 0.9939576
[2,] 13 12 1 0.9939576
[3,] 14 12 1 0.9939576
[4,] 15 14 1 0.9939576
[5,] 16 14 1 0.9939576
[6,] 17 14 1 0.9939576
[7,] 18 14 1 0.9939576
[8,] 30 29 1 0.9939576
[9,] 31 29 1 0.9939576
[10,] 32 29 1 0.9939576
[11,] 11 9 2 0.9819270
[12,] 19 14 2 0.9819270
[13,] 20 14 2 0.9819270
[14,] 21 14 2 0.9819270
[15,] 22 14 2 0.9819270
[16,] 23 14 2 0.9819270
[17,] 24 14 2 0.9819270
[18,] 25 14 2 0.9819270
[19,] 12 7 3 0.9640739
[20,] 12 9 3 0.9640739
[21,] 34 12 3 0.9640739
[22,] 26 14 3 0.9640739
[23,] 8 7 4 0.9406588
[24,] 29 12 4 0.9406588
[25,] 27 14 4 0.9406588
[26,] 28 14 4 0.9406588
[27,] 33 29 4 0.9406588
[28,] 7 1 5 0.9120671
[29,] 7 2 5 0.9120671
[30,] 5 4 5 0.9120671
[31,] 7 3 6 0.8787358
[32,] 7 4 7 0.8412104
[33,] 7 6 9 0.7560227
attr(,"freq")
[1] 1 1 1 1 1 3 1 1 3 1 1 3 1 9 2 1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 1 1
attr(,"labels")
[1] "I" "II" "III" "IV" "V" "VI" "VII" "VIII" "IX" "X"
[11] "XI" "XII" "XIII" "XIV" "XV" "XVI" "XVII" "XVIII" "XIX" "XX"
[21] "XXI" "XXII" "XXIII" "XXIV" "XXV" "XXVI" "XXVII" "XXVIII" "XXIX" "XXX"
[31] "XXXI" "XXXII" "XXXIII" "XXXIV"
attr(,"class")
[1] "haploNet"