2017-03-15 20 views
0

我跟着的igraph的saving plot文檔工作,但我通過圖列表需要循環,這是行不通的:的igraph保存情節不輸出文件名作爲一個對象

for (f in flist) { 
    df <- read.table(f, header=TRUE, sep='\t', quote='', comment.char='') 
    png <- paste0(f, '.png') 
    g <- graph_from_data_frame(df, directed = FALSE) 
    plot(g, png) 
} 

我試過plot(g, png)plot(g, file=png)plot(g, save=png)plot.igraph(g, png),plot.igraph(g, file=png),plot.igraph(g, save=png)。它們都不起作用。

Error in if (axes) { : argument is not interpretable as logical 

或者

Error in i.parse.plot.params(graph, list(...)) : 
Unknown plot parameters: save 
+2

要檢查igraph'的'Python文檔。爲了將你的圖表保存在一個文件中,就像任何常規的R圖一樣。您打開文件,調用繪圖並關閉設備。像:'png(「myfile.png」); plot(mygraph); dev.off()',你會得到'myfile.png'與你的情節。 – nicola

+0

對不起,我的壞。剛剛查看R igraph頁面:http://igraph.org/r/doc/plot.common.html,未找到輸出參數。將嘗試你的建議! – leoce

回答

0
for (f in flist) { 
    df <- read.table(f, header=TRUE, sep='\t', quote='', comment.char='') 
    png <- paste0(f, '.png') 
    g <- graph_from_data_frame(df, directed = FALSE) 
    plot(g, png) 
    png("/YOUR PATH/XXX.png") 
    plot(g) 
    dev.off() 
}