【问题标题】:call R ggplot with Rexcel用 Rexcel 调用 R ggplot
【发布时间】:2014-03-18 21:28:44
【问题描述】:

我点击了一个 Excel 宏按钮,该按钮使用 RExcel 执行生成矩阵的 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()”。我想在 excel 中完成这项工作...

【问题讨论】:

    标签: r vba ggplot2 rexcel


    【解决方案1】:

    虽然很尴尬,但如果其他人有同样的问题,我会留下它

    print(drawIt())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-20
      • 2020-05-27
      相关资源
      最近更新 更多