[英]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.