javascript - R中负值的dygraph条形图

标签 javascript r r-dygraphs

我有时间序列数据,我想在 R 中使用 dygraphs 绘制条形图而不是线条。我正在使用来自 dygraphs documentation 的以下 plotter 建议.

dyBarChart <- function(dygraph) {
  dyPlotter(dygraph = dygraph,
            name = "BarChart",
            path = system.file("plotters/barchart.js",
                               package = "dygraphs"))
}

我遇到的问题是表示负值。
有了线图,这个 dygraph() 就可以正常工作了:

dygraph(test)

enter image description here

但是,当我们添加条形图时,没有绘制任何内容并返回警告:

dygraph(z)  %>%  dyBarChart() 
There were 14 warnings (use warnings() to see them)
> warnings()

Warning messages:
1: In normalizePath(path) : path[1]="": No such file or directory
2: In file.copy(from, to, overwrite = TRUE, recursive = isdir) : too deep nesting
3: In file.copy(from, to, overwrite = TRUE, recursive = isdir) : too deep nesting...

在 R dygraph 条形图中绘制负值是否有已知的解决方法?

这是示例数据:

> dput(test)
structure(c(-6L, 0L, -4L, -1L, 2L, 0L, 18L, -3L, -2L, -1L, -2L, 
1L, -22L, -5L, -1L, 3L, 11L, 2L, -2L, 5L, -3L, -1L, -2L, 0L, 
12L), index = structure(c(1521217200, 1521217800, 1521218400, 
1521219000, 1521219600, 1521220200, 1521220800, 1521221400, 1521222000, 
1521222600, 1521223200, 1521223800, 1521224400, 1521225000, 1521225600, 
1521226200, 1521226800, 1521227400, 1521228000, 1521228600, 1521229200, 
1521229800, 1521230400, 1521231000, 1521231600), class = c("POSIXct", 
"POSIXt"), tzone = ""), class = "zoo")

最佳答案

如果您尝试提供的链接中的示例,您会发现它不起作用。但感谢:How do you create a bar and line plot with R dygraphs?

这是让您的代码正常工作的正确 dyBarChart 函数。

dyBarChart <- function(dygraph) {
    dyPlotter(
        dygraph = dygraph,
        name = "BarChart",
        path = system.file("examples/plotters/barchart.js",package = "dygraphs")
    )
}

dygraph(test) %>% dyBarChart() 

关于javascript - R中负值的dygraph条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49371111/

相关文章:

javascript - 在 React.js 中使用 onKeyPress 而不是 onKeyUp 检测何时按下删除或退格键

javascript - 捕捉 SVG 路径动画

r - 在 Caret 中安装 bartMachine 获取长度为零的参数/维数不正确

r - 在 R-Markdown 中的网格上显示多个 dygraph

dygraphs - 如何在 dygraphs 中绘制烛台 + 滚轴 [r]

c# - 具有特定时区的 Javascript 整数到日期时间

javascript - 停止 Chrome 扩展中的内容脚本

r - 从具有不同元素数量的 xml 创建数据框

r - 将闭包转换为 R 中的字符

r - Shiny 中带有 htmltools 的 dygraphs 列表