我点击一个excel宏按钮,它使用reexcel来执行一个生成矩阵的R脚本
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] 0 0 -3 -3 -3 -3 -2
[2,] 0 0 0 0 4 4 4
[3,] 0 0 0 1 2 1 2
[4,] 0 0 0 0 0 0 1
[5,] 0 0 0 0 1 1 1
[6,] 0 0 0 0 1 1 1
[7,] 0 0 0 0 0 0 0
[8,] 0 0 0 0 0 0 0
[9,] 0 0 0 0 0 0 0
[10,] 0 0 0 0 0 0 1
[11,] 0 0 0 0 0 0 1
[12,] 0 1 1 1 1 1 1
[13,] 0 0 0 0 0 0 0
[14,] 0 0 0 0 0 0 0
[15,] 0 0 0 0 0 0 0
[16,] 0 -1 3 3 3 4 3
[17,] 0 1 2 2 2 1 0
[18,] 0 0 0 0 0 0 0
[19,] 0 -1 -2 -2 -2 -1 -1
[20,] 0 -2 -2 -3 -3 -5 -4
[21,] 0 0 0 0 0 0 0
[22,] 0 0 0 0 0 0 0
[23,] 0 1 1 1 1 1 1
[24,] 0 0 1 1 1 0 1
[25,] 0 0 1 1 1 0 1
[26,] 0 0 1 1 1 1 2
[27,] 0 0 0 0 0 0 1
[28,] 0 0 0 0 0 0 0
[29,] 0 0 0 0 0 0 0
[30,] 0 0 0 0 0 0 0
[31,] 0 0 0 0 0 0 0
,我把它改成data.frame。在
前面设置browser()ggplot(melt(graphPrep),aes(value,fill=variable)) + geom_histogram(position = "dodge",binwidth = 1/(buckWidth-1)) + scale_x_continuous(breaks = min(graphPrep):max(graphPrep))
你可以使用5作为buckWidth,如果你复制
则使用-5:5然后将这一行输入R,按回车键,这就形成了一个漂亮的图。但是,如果我只是按几次"n"来尝试执行这一行(或完全删除浏览器),则图形永远不会显示。
我想让这个完全可以从excel中执行,但我定义的是
drawIt <- function()
{
ggplot(melt(graphPrep),aes(value,fill=variable)) + geom_histogram(position = "dodge",binwidth = 1/(buckWidth-1)) + scale_x_continuous(breaks = min(graphPrep):max(graphPrep))
}
并使用户在r控制台中"drawIt()"。
尽管这很尴尬,但我还是把它留在这里,以防其他人遇到同样的问题
print(drawIt())