如何使用图形来源的数据名称为绘图命名?
How can I title a plot using the name of the data that the graph comes from?
我有一个 igraph objects 的列表,我正在从中生成图(使用 forloop),我想给每个图一个标题,该标题来自 object 它来从。有谁知道我该怎么做?
这是我当前的代码:
for (i in glst){
i=delete.vertices(i,which(degree(i)<1))
plot(i)
legend(x=-2, y=-0.3, c('nest', 'tree'), pch=21,
col="#777777", pt.bg= c('orangered3','forestgreen'), pt.cex=2,
cex=1, bty="n", ncol=1)
}
其中 glst 是 igraph objects 的列表(称为 colony12012、colony12013a..... 等)
您可以尝试循环遍历 names(glst)
,因此 for (i in glst)
变为 for (name in names(glst))
、
然后i=delete.vertices(i,which(degree(i)<1))
变成i = delete.vertices(glst[[name]], which(degree(glst[[name]]) < 1))
,所以你可以添加title(main = name)
。
我有一个 igraph objects 的列表,我正在从中生成图(使用 forloop),我想给每个图一个标题,该标题来自 object 它来从。有谁知道我该怎么做?
这是我当前的代码:
for (i in glst){
i=delete.vertices(i,which(degree(i)<1))
plot(i)
legend(x=-2, y=-0.3, c('nest', 'tree'), pch=21,
col="#777777", pt.bg= c('orangered3','forestgreen'), pt.cex=2,
cex=1, bty="n", ncol=1)
}
其中 glst 是 igraph objects 的列表(称为 colony12012、colony12013a..... 等)
您可以尝试循环遍历 names(glst)
,因此 for (i in glst)
变为 for (name in names(glst))
、
然后i=delete.vertices(i,which(degree(i)<1))
变成i = delete.vertices(glst[[name]], which(degree(glst[[name]]) < 1))
,所以你可以添加title(main = name)
。