我是R的新手,想要使用一个文件绘制多个直方图,另一个用于图例。
这是我的代码(我知道这是一团糟所以请耐心等待我):
filenames<-c("SWZG1THOU1Q", "SWZG1THOU2Q", "SWZG1THOU3Q", "SWZG1THOU4Q", "SWZG1THOU5Q", "SWZG1THOU6Q", "SWZG1THOU7Q", "SWZG1THOU8Q", "SWZG1THOU9Q", "SWZG1THOU10Q")
textfiles<-c("WeightZimbabweGhana1THOU1Q.fst.idx.txt", "WeightZimbabweGhana1THOU2Q.fst.idx.txt", "WeightZimbabweGhana1THOU3Q.fst.idx.txt", "WeightZimbabweGhana1THOU4Q.fst.idx.txt", "WeightZimbabweGhana1THOU5Q.fst.idx.txt", "WeightZimbabweGhana1THOU6Q.fst.idx.txt", "WeightZimbabweGhana1THOU7Q.fst.idx.txt", "WeightZimbabweGhana1THOU8Q.fst.idx.txt", "WeightZimbabweGhana1THOU9Q.fst.idx.txt", "WeightZimbabweGhana1THOU10Q.fst.idx.txt")
for (i in filenames) {
a<-read.table(i, head=T, sep="\t")
pdf(paste("plot", i, ".pdf", sep = ""))
hist(a$Nsites, main=i, breaks=20, xlab="Fst")
for (k in textfiles) {
b<-read.table(k, head=T)
d<-paste("Weighted Fst",b)
legend("topright", as.graphicsAnnot(d))
}#2
dev.off()
}#1
我只想在文本文件中使用相应的文件作为文件名的图例。 我感谢任何能帮助我的人。