【问题标题】:R-Script in RapidminerRapidminer 中的 R 脚本
【发布时间】:2017-11-06 10:38:15
【问题描述】:

也许有人可以帮助我解决我的问题。

我正在使用 RapidMiner 和 R-Script Operator,并使用以下 R-Script 处理 369 x 258 出现矩阵:

# 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 export igraph rapidminer


    【解决方案1】:

    我无法让 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))
    }
    

    【讨论】:

      猜你喜欢
      • 2017-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多