请考虑以下data.frame
:
POP1 POP2 FST
ES13-15 ES16-18 0.0109
ES19-21 SA7-9 0.0587
SA7-9 SA13-15 0.0287
ES10-12 ES37-38 0.0816
ES34-36 ES37-38 0.0205
ES28-30 ES37-38 0.0425
ES22-24 ES25-27 0.0108
ES19-21 SA22-25 0.0940
ES6-8 ES13-15 0.0081
ES1-3 ES7-9 0.0418
ES7-9 ES16-18 0.0224
ES19-21 ES37-38 0.0894
ES1-3 ES34-36 0.0874
ES19-21 ES25-27 0.0320
ES19-21 SA19-21 0.1184
SA7-9 SA16-18 0.0361
ES13-15 SA19-21 0.0852
ES22-24 SA7-9 0.0193
ES28-30 SA7-9 0.0335
ES4-6 ES34-36 0.0794
这里是dput
:
structure(list(POP1 = c("ES1-3", "SA4-6", "ES31-33", "ES1-3",
"ES34-36", "SA1-3", "ES6-8", "ES7-9", "ES25-27", "ES7-9", "SA10-12",
"ES1-3", "ES10-12", "ES10-12", "ES22-24", "ES10-12", "ES37-38",
"ES34-36", "ES4-6", "ES16-18"), POP2 = c("ES10-12", "SA16-18",
"ES37-38", "SA13-15", "ES37-38", "SA16-18", "ES34-36", "ES10-12",
"SA1-3", "SA22-25", "SA16-18", "ES6-8", "SA13-15", "SA22-25",
"SA13-15", "ES31-33", "SA10-12", "SA4-6", "ES22-24", "SA13-15"
), FST = c(0.0123, 0.0531, 0.039, 0.0744, 0.0205, 0.0831, 0.0678,
0.0257, 0.045, 0.0635, 0.0138, 0.0193, 0.0782, 0.0726, 0.0522,
0.0612, 0.0719, 0.0624, 0.0255, 0.0819)), row.names = c(4L, 214L,
178L, 18L, 187L, 208L, 51L, 61L, 158L, 78L, 223L, 2L, 92L, 95L,
150L, 85L, 199L, 189L, 28L, 123L), class = "data.frame")
我想生成一个包含POP1和POP2列的图,并生成一个像这样的区块链图:
其中每个块以行方式表示我的data.frame
的成对关系。例如,第一行ES13-15将是图片中与ES16-18链接的块。如果能够站在链接这些块的行的顶部,FST的价值将是巨大的。在前一种情况下,值0.0109将位于链接上述块的线的上方。
也可以使用一些分叉代码。
答案 0 :(得分:1)
您可以尝试使用“ igraph”软件包:
Using your `dput()` output, which is different from data.frame you have shared.
library(igraph)
df = structure(list(POP1 = c("ES1-3", "SA4-6", "ES31-33", "ES1-3",
"ES34-36", "SA1-3", "ES6-8", "ES7-9", "ES25-27", "ES7-9", "SA10-12",
"ES1-3", "ES10-12", "ES10-12", "ES22-24", "ES10-12", "ES37-38",
"ES34-36", "ES4-6", "ES16-18"), POP2 = c("ES10-12", "SA16-18",
"ES37-38", "SA13-15", "ES37-38", "SA16-18", "ES34-36", "ES10-12",
"SA1-3", "SA22-25", "SA16-18", "ES6-8", "SA13-15", "SA22-25",
"SA13-15", "ES31-33", "SA10-12", "SA4-6", "ES22-24", "SA13-15"
), FST = c(0.0123, 0.0531, 0.039, 0.0744, 0.0205, 0.0831, 0.0678,
0.0257, 0.045, 0.0635, 0.0138, 0.0193, 0.0782, 0.0726, 0.0522,
0.0612, 0.0719, 0.0624, 0.0255, 0.0819)), row.names = c(4L, 214L,
178L, 18L, 187L, 208L, 51L, 61L, 158L, 78L, 223L, 2L, 92L, 95L,
150L, 85L, 199L, 189L, 28L, 123L), class = "data.frame")
g<-graph_from_data_frame(d = df[,c(1,2)],directed = TRUE)
plot(g,edge.arrow.size=0.1,vertex.shape="rectangle")