簡體   English   中英

Rapidminer中的R腳本

[英]R-Script in Rapidminer

也許有人可以幫助我解決我的問題。

我正在使用RapidMiner和R-Script Operator,並使用以下R-Script處理369 x 258出現的Matix:

# rm_main is a mandatory function, 
# the number of arguments has to be the number of input ports (can be none)
rm_main = function(data)
{
total_occurrence <- colSums(data)
data_matrix <- as.matrix(data)
co_occurrence <- t(data_matrix) %*% data_matrix
library(igraph)
graph <- graph.adjacency(co_occurrence,
                          weighted = TRUE,
                          mode="undirected",
                          diag = FALSE)
tkplot(graph,
        vertex.label=names(data),
        vertex.size=total_occurrence*1,
        edge.width=E(graph)$weight*1,)

dev.copy (tk_postscript, file= '/home/knecht/r-graph.pdf')
dev.off()
}

創建圖形后,該過程終止,並顯示錯誤消息“無法從空設備復制”。

所以我的問題是,如何在諸如postscript或png的文件中打印圖形?

親切的問候

托比亞斯

我無法使R代碼在RapidMiner之外運行,因此我進行了一些更改以進行打印,而不是使用tkplot(這是交互式的,因此可能仍然很麻煩)。

我還在代碼中添加了一些簡單的數據,以使示例可以重現。

將創建的png文件的位置更改為要存儲結果的位置(RapidMiner使用臨時本地文件夾,因此您必須明確說明該位置)。

rm_main = function(data)
{
    data2 = matrix(c(1,2,3,1,2,1), nrow = 2, ncol = 3)
    total_occurrence <- colSums(data2)
    data_matrix <- as.matrix(data2)
    co_occurrence <- t(data_matrix) %*% data_matrix
    library(igraph)
    graph <- graph.adjacency(co_occurrence,
                      weighted = TRUE,
                      mode="undirected",
                      diag = FALSE)
    png('c:/temp/r-graph.png')                     
    plot(graph,
       vertex.label=names(data2),
        vertex.size=total_occurrence*1,
        edge.width=E(graph)$weight*1,)
    dev.off()
return(list(data))
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM