问题描述
有多个条件,我想获取下面所示条件的所有组合的图。我可以使用特定名称为提供的条件的各种组合创建图。但是,我想对图进行排序的是特定目录/子目录。
- 有六个条件,这是为给定条件创建目录的代码。
for (k in 1:length(carryingcapcity)) {
for (r1 in 1:length(growthrate)){
for (mut in 1:length(mutationrate)) {
for(s_coef in 1:length(selectioncoef)) {
for (mig in 1:length(migrationrate)){
for (com in 1:length(competition)) {
dir.create(path= paste0("D:/Vedant/MSc_Bhehaviour/Special_Module_Modeling/My project/Figurs/Carrying_cap",k,"/R_",r1,"/Mut",mut,"/Sel",s_coef,"/Mig",mig),recursive = TRUE)
}
}
}
}
}
}
- 现在我要在循环中的各个子目录中导出特定组合的图。例如,plot_name: K_1000_R_1_Mut_0.001_Sel_0.01_Mig_0_Com_0.1 ,我想保存到目录“ ../ Carrying_cap_1 / R_1 / Mut_1 / Sel_1 / Mig_1” ,然后输入最后一个子目录Mig_1将包含所有数字。 我想在循环中更改目录以使用不同的组合,例如“ ../ Carrying_cap_1 / R_1 / Mut_2 / Sel_1 / Mig_2 ” 。
(*有条件列表和其他列表*)
获取多个图的代码。
for (ii in 1:length(carryingcapcity)) {
for (r1 in 1:length(growthrate)){
for (mut in 1:length(mutationrate)) {
for(s_coef in 1:length(selectioncoef)) {
for (mig in 1:length(migrationrate)){
for (com in 1:length(competition)) {
{
name1 = as.character(carryingcapcity[ii])
name2 = as.character(growthrate[r1])
name3 = as.character(mutationrate[mut])
name4 = as.character(selectioncoef[s_coef])
name5 = as.character(migrationrate[mig])
name6 = as.character(competition[com])
seqname = as.character(com)
filepath = file.path("D:/Vedant/MSc_Bhehaviour/Special_Module_Modeling/My project/Figurs",Carrying_cap[[ii]]) paste("K",name1,"R",name2,"Mut",name3,"Sel",name4,"Mig",name5,"Com",name6,".jpg",sep = ("_"))
jpeg(file = filepath )
matplot(listofalldata[[ii]][[r1]][[mut]][[s_coef]][[mig]][[com]][[1]][1],listofalldata[[ii]][[r1]][[mut]][[s_coef]][[mig]][[com]][[1]][2],type = 'l',ylim = c(0,1000),xlab = 'Time',ylab = 'Population size',lwd = 2 )
matlines(listofalldata[[ii]][[r1]][[mut]][[s_coef]][[mig]][[com]][[1]][1],listofalldata[[ii]][[r1]][[mut]][[s_coef]][[mig]][[com]][[1]][5],col='blue',lwd = 2)
matlines(listofalldata[[ii]][[r1]][[mut]][[s_coef]][[mig]][[com]][[1]][1],listofalldata[[ii]][[r1]][[mut]][[s_coef]][[mig]][[com]][[1]][8],col='green',lwd = 2)
legend("bottomright",legend = c("Speceis Sp1_Host H1","Speceis Sp1_Host H2","Speceis Sp2_Host H2"),col = c("black","blue","green"),lwd=c(4,4,4))
dev.off()
}
}
}
}
}
}
}
如何在循环中更改文件路径?
谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)