Javascript R为负值的动态图条形图

Javascript R为负值的动态图条形图,javascript,r,r-dygraphs,Javascript,R,R Dygraphs,我有一个时间序列数据,我想用条形图而不是线来绘制R中的dygraphs。我正在使用以下绘图仪的建议 但是,当我们添加条形图时,不会绘制任何内容并返回警告: dygraph(z) %>% dyBarChart() There were 14 warnings (use warnings() to see them) > warnings() Warning messages: 1: In normalizePath(path) : path[1]="": No such fi

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

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

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动态图条形图中绘制负值是否有已知的解决方法

以下是示例数据:

> 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")

如果您在提供的链接中尝试该示例,您将看到它不起作用。但多亏了:

下面是正确的dyBarChart函数,供您的代码使用

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

dygraph(test) %>% dyBarChart() 
dyBarChart%dyBarChart()
> 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")
dyBarChart <- function(dygraph) {
    dyPlotter(
        dygraph = dygraph,
        name = "BarChart",
        path = system.file("examples/plotters/barchart.js",package = "dygraphs")
    )
}

dygraph(test) %>% dyBarChart()